Skip to content

Commit

Permalink
Added article helper method, removed tbody block.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmckissock committed Jul 3, 2024
1 parent b9d3026 commit e15e983
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
1 change: 1 addition & 0 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 6 additions & 6 deletions app/views/articles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
</td>
<td valign="top" class="votelinks">
<center>
<%= 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 %>
<i class="fas fa-arrow-up"></i>
<% 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 %>
<i class="fas fa-arrow-down"></i>
<% end %>
</center>
</td>
<td class="title">
<%= link_to @article.title, @article.link, target: "_blank" %>
<%= link_to article.title, article.link, target: "_blank" %>
</td>
</tr>
<tr>
<td colspan="2"></td>
<td class="subtext">
<span id="score-Article-<%= @article.id %>" class="score"><%= @article.score %> points</span>
by <%= link_to @article.user.name, user_path(@article.user) %>
<span class="age"><%= time_ago_in_words(@article.created_at) %> ago</span>
<span id="score-Article-<%= article.id %>" class="score"><%= article.score %> points</span>
by <%= link_to article.user.name, user_path(article.user) %>
<span class="age"><%= time_ago_in_words(article.created_at) %> ago</span>
</td>
</tr>
<tr style="height:10px"></tr>
Expand Down
61 changes: 30 additions & 31 deletions app/views/users/comments.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,36 @@
<tbody>
<% current_page = params[:page].present? ? params[:page].to_i : 1 %>
<% @comments.each_with_index do |comment, index| %>
<tbody>
<tr>
<td align="right">
<span class="rank"><%= (current_page-1) * 20 + index + 1 %>.</span>
</td>
<td valign="top" class="votelinks">
<center>
<%= 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 %>
<i class="fas fa-arrow-up"></i>
<% 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 %>
<i class="fas fa-arrow-down"></i>
<% end %>
</center>
</td>
<td valign="top">
<%= comment.text %>
</td>
</tr>
<tr>
<td colspan="2"></td>
<td class="subtext">
<span id="score-Comment-<%= comment.id %>"><%= comment.score %> points</span>
by <%= link_to comment.user.name, user_path(comment.user) %>
<span class="age"><%= time_ago_in_words(comment.created_at) %> ago</span>
|
<%= link_to(" reply", article_comment_path(comment.article, comment))%>
</td>
</tr>
<tr style="height:5px"></tr>

<tr>
<td align="right">
<span class="rank"><%= (current_page-1) * 20 + index + 1 %>.</span>
</td>
<td valign="top" class="votelinks">
<center>
<%= 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 %>
<i class="fas fa-arrow-up"></i>
<% 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 %>
<i class="fas fa-arrow-down"></i>
<% end %>
</center>
</td>
<td valign="top">
<%= comment.text %>
</td>
</tr>
<tr>
<td colspan="2"></td>
<td class="subtext">
<span id="score-Comment-<%= comment.id %>"><%= comment.score %> points</span>
by <%= link_to comment.user.name, user_path(comment.user) %>
<span class="age"><%= time_ago_in_words(comment.created_at) %> ago</span>
|
<%= link_to(" reply", article_comment_path(comment.article, comment))%>
</td>
</tr>
<tr style="height:5px"></tr>

<% end %>
</tbody>
</table>
Expand Down

0 comments on commit e15e983

Please sign in to comment.