Answer the question
In order to leave comments, you need to log in
How to display articles in the correct order?
Displays the oldest topic first. The only idea is to rewrite the loop so that it outputs by id (from last to first), but this is no longer the rails way. I looked at the github sources of other blogs, the volume is also output through "each do".
ps do not throw slippers, I'm only at the beginning of the path of mastering ruby
<% @articles.each do |article| %>
<h1><%= link_to article.title, article_path(article) %></h1>
<%= article.created_at.strftime("%d %b. %Y") %>
<%= raw article.tag_list.map { |t| link_to t, tag_path(t)}.join(', ') %>
<div class="well">
<%= article.body %>
<p><%= link_to 'Продолжить чтение... ', article_path(article) %></p>
</div>
<% end %>
<%= will_paginate @articles, previous_label: "← Назад", next_label: "Вперед →" %>
Answer the question
In order to leave comments, you need to log in
In controller:
By the way, in view you can do:
<%= render @articles %>
<%= will_paginate @articles, previous_label: "← Назад", next_label: "Вперед →" %>
<h1><%= link_to article.title, article_path(article) %></h1>
<%= article.created_at.strftime("%d %b. %Y") %>
<%= raw article.tag_list.map { |t| link_to t, tag_path(t)}.join(', ') %>
<div class="well">
<%= article.body %>
<p><%= link_to 'Продолжить чтение... ', article_path(article) %></p>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question