jeudi 20 août 2015

How can i reverse dates on rails 4?

I want to be able to reverse this list so instead of it showing the first date I want the latest date to show up on top. So instead of the 19th I want the 21st on top.

19 August 2015

Creeme

Deja Tu Envidia

Debarata

20 August 2015

Ginza

Versace

21 August 2015

Cuando Le Doy ft. El Súper Nuevo

(The Controller)

def index
    @videos = Video.all.order("cached_votes_up DESC, created_at DESC")
    @topvideo = Video.all.order("cached_votes_up DESC, created_at DESC")


    @items = Video.order("cached_votes_up DESC, created_at DESC").where("created_at ", Time.zone.now.beginning_of_day)
    @items_by_day = @items.group_by { |t| t.created_at.beginning_of_day }
end

(The View)

<% @items_by_day.sort.each do |day, items| %>
<h1><%= day.strftime("%d %B %Y") %></h1>
<table class="table table-striped">
    <thead>
        <tr>
            <th>Item</th>
            <th></th>           
       </tr>
    </thead>
    <% for item in items %>
    <tbody>
        <tr>
            <td><%= item.title %></td>
        </tr>
    </tbody>
    <% end %>
</table>
<% end %>

Aucun commentaire:

Enregistrer un commentaire