D
D
destroy_sys2015-01-17 12:11:41
Ruby on Rails
destroy_sys, 2015-01-17 12:11:41

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

1 answer(s)
V
Viktor Vsk, 2015-01-17
@destroy_sys

In controller:
By the way, in view you can do:

<%= render @articles %>
<%= will_paginate @articles, previous_label: "← Назад", next_label: "Вперед →" %>

And create a views/articles/_article.html.erb partial
and in it:
<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 question

Ask a Question

731 491 924 answers to any question