diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index ad07e63..306d8ba 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -1,5 +1,6 @@ class ArticlesController < ApplicationController before_action :authorized, only: [:new, :create, :upvote, :downvote] + helper_method :article def index @articles = Article.order(created_at: :desc).page(params[:page]).per(20) diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb index 42812f3..dbab6d7 100644 --- a/app/views/articles/show.html.erb +++ b/app/views/articles/show.html.erb @@ -9,24 +9,24 @@
- <%= button_to upvote_article_path(@article), method: :post, class: "btn btn-sm upvote-button", data: { votable_type: 'Article', votable_id: @article.id } do %> + <%= button_to upvote_article_path(article), method: :post, class: "btn btn-sm upvote-button", data: { votable_type: 'Article', votable_id: article.id } do %> <% end %> - <%= button_to downvote_article_path(@article), method: :post, class: "btn btn-sm downvote-button", data: { votable_type: 'Article', votable_id: @article.id } do %> + <%= button_to downvote_article_path(article), method: :post, class: "btn btn-sm downvote-button", data: { votable_type: 'Article', votable_id: article.id } do %> <% end %>
- <%= link_to @article.title, @article.link, target: "_blank" %> + <%= link_to article.title, article.link, target: "_blank" %> - <%= @article.score %> points - by <%= link_to @article.user.name, user_path(@article.user) %> - <%= time_ago_in_words(@article.created_at) %> ago + <%= article.score %> points + by <%= link_to article.user.name, user_path(article.user) %> + <%= time_ago_in_words(article.created_at) %> ago diff --git a/app/views/users/comments.html.erb b/app/views/users/comments.html.erb index 9cbfe90..ca46d62 100644 --- a/app/views/users/comments.html.erb +++ b/app/views/users/comments.html.erb @@ -5,37 +5,36 @@ <% current_page = params[:page].present? ? params[:page].to_i : 1 %> <% @comments.each_with_index do |comment, index| %> - - - - <%= (current_page-1) * 20 + index + 1 %>. - - -
- <%= button_to upvote_article_comment_path(comment), method: :post, class: "btn btn-sm upvote-button", data: { votable_type: 'Comment', votable_id: comment.id, article_id: comment.article.id } do %> - - <% end %> - <%= button_to downvote_article_comment_path(comment), method: :post, class: "btn btn-sm downvote-button", data: { votable_type: 'Comment', votable_id: comment.id, article_id: comment.article.id } do %> - - <% end %> -
- - - <%= comment.text %> - - - - - - <%= comment.score %> points - by <%= link_to comment.user.name, user_path(comment.user) %> - <%= time_ago_in_words(comment.created_at) %> ago - | - <%= link_to(" reply", article_comment_path(comment.article, comment))%> - - - - + + + <%= (current_page-1) * 20 + index + 1 %>. + + +
+ <%= button_to upvote_article_comment_path(comment), method: :post, class: "btn btn-sm upvote-button", data: { votable_type: 'Comment', votable_id: comment.id, article_id: comment.article.id } do %> + + <% end %> + <%= button_to downvote_article_comment_path(comment), method: :post, class: "btn btn-sm downvote-button", data: { votable_type: 'Comment', votable_id: comment.id, article_id: comment.article.id } do %> + + <% end %> +
+ + + <%= comment.text %> + + + + + + <%= comment.score %> points + by <%= link_to comment.user.name, user_path(comment.user) %> + <%= time_ago_in_words(comment.created_at) %> ago + | + <%= link_to(" reply", article_comment_path(comment.article, comment))%> + + + + <% end %>