ruby - How do I group content according to date (Rails) -


I am trying to display group content that is simultaneously on display for display, such as date Only once is posted and

October 14, 2009
item 3
item 3 content

item 2
item 2 Content

October 13, 2009 item 1
item 3 content

How can I view it? (Suppose @ etams are being passed by controller, which contains all the items)

I have tried the group, but I can not get it to work as it seems

Code in question:

To see the problem in a live deployment

/ P>

1) Replace line 5 with app / controllers / items_controller.rb:

  @items = item (ADRE = & gt; "h Replace DESC ")  

2) Replace row 3-14 of app / scene / item / index.html.erb:

  & lt; % Date = 1.day.from_now (@ items.first.date.to_date) Rescue zero # days @ increments @ item.each do item | If the date & gt; Item.date.to_date date = item.date.to_date% & gt; & Lt; Div style = "background: # 81 beef 7; margin-top: 5px; margin-down: 5px;" Class = "round" & gt; & Lt; B & gt; & Lt; Span style = "padding: 5px" & gt; & Lt;% = h date% & gt; & Lt; / Span & gt; & Lt; / B & gt; & Lt; / Div & gt; & Lt;% end% & gt; & Lt; P & gt; & Lt; I & gt; & Lt;% = h Items Time% & gt; - & lt; / I & gt; & Lt;% = link_to "# {item.title}", item.link% & gt; & Lt; Br> & Lt; A href = "/ item / <% = item.id%" gt; Gt; & Gt; & Lt; Span category = "subtext" style = "margin-left: 55px" & gt; By & lt;% = item.user user name% & gt; | & Lt;% = item.comments.count% & gt; Comments & lt; / Span & gt; & Lt; / A & gt; & Lt; / P & gt; & Lt;% end # items_each% & gt;  

In this approach, you are making a simple comparison for sorting DB and grouping for sorting.

PS: I do not think that this is a good idea of ​​your name in the database column 'Date' in some databases as 'date' is a reserved keyword.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -