ruby on rails - slice each day ROR -
this question has reply here:
how grouping day instead of date? 4 answersim creating time line columns table. @ moment time line display each column ordered "created_at" field. want piece each day this:
today content -| | |- content | content -| | yesterday | |- content | content -|
at moment using code
<ul> <% @timeline.each |timeline| %> <li> <%= timeline.title %> </li> <% end %> </ul>
i want "each_slice(5)" function. hope can tell me how this. in advance.
you can grouping array ruby group_by
:
@timeline.group_by { |el| el.created_at.to_date.to_s(:db) }
note: assume @timeline sorted.
probably, method reusable, improve place in models like:
def self.to_grouped_by_day group_by { |el| el.created_at.to_date.to_s(:db) } end
and phone call in controller.
ruby-on-rails ruby
No comments:
Post a Comment