# Separate rows in view depending its date

**URL:** <https://www.ruby-forum.com/t/separate-rows-in-view-depending-its-date/161993>\
**Category:** Rails\
**Created:** [March 4, 2009, 4:47pm UTC](https://www.ruby-forum.com/t/separate-rows-in-view-depending-its-date/161993 "2009-03-04T16:47:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [March 4, 2009, 4:47pm UTC](https://www.ruby-forum.com/t/separate-rows-in-view-depending-its-date/161993/1 "2009-03-04T16:47:04Z")

</div>

Hi,

I would like to hear your opinions about how do you think I can  
implement this.  
I have a @events array where I have events each one with its datetime,  
and ordered by it.  
I would like to show a list of these events in a table. I would like to  
put a blank row in the table after each group of events with the same  
date.  
I don’t know if it is better to separate the events in groups in the  
controller or if I can use an ‘if’ in the view to insert this blank row.

Thanks.

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [March 4, 2009, 5:19pm UTC](https://www.ruby-forum.com/t/separate-rows-in-view-depending-its-date/161993/2 "2009-03-04T17:19:51Z")

</div>

2009/3/4 Juan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I don’t know if it is better to separate the events in groups in the  
> controller or if I can use an ‘if’ in the view to insert this blank row.

I would suggest this is to do with how you want to view the data, it is  
not  
inherent in the data itself, so it should go in the view.

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [March 4, 2009, 7:40pm UTC](https://www.ruby-forum.com/t/separate-rows-in-view-depending-its-date/161993/3 "2009-03-04T19:40:14Z")

</div>

Ok. That makes sense to me. Can I store values in variables in the view?  
I think it would be possible by storing the datetime of the previous  
event and comparing it with the current event datetime. I think what I  
want to do is similar to pagination…

Colin L. wrote:

> 2009/3/4 Juan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> > I don’t know if it is better to separate the events in groups in the  
> > controller or if I can use an ‘if’ in the view to insert this blank row.
> 
> I would suggest this is to do with how you want to view the data, it is  
> not  
> inherent in the data itself, so it should go in the view.

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [March 4, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/separate-rows-in-view-depending-its-date/161993/4 "2009-03-04T20:09:28Z")

</div>

You can write pretty much any ruby in the view, local vars are no  
problem. I  
feel there may be an elegant way to skip a row or otherwise leave a gap  
on  
date change but at the moment it escapes me. Any suggestions from those  
with  
more experience?

2009/3/4 Juan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [March 4, 2009, 8:56pm UTC](https://www.ruby-forum.com/t/separate-rows-in-view-depending-its-date/161993/5 "2009-03-04T20:56:43Z")

</div>

On Wed, 2009-03-04 at 19:08 +0000, Colin L. wrote:

> You can write pretty much any ruby in the view, local vars are no  
> problem. I feel there may be an elegant way to skip a row or otherwise  
> leave a gap on date change but at the moment it escapes me. Any  
> suggestions from those with more experience?

CSS. Wrap each date-group in a

 and style it with  
a top/bottom margin to get the spacing you’re looking for.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [March 5, 2009, 8:33am UTC](https://www.ruby-forum.com/t/separate-rows-in-view-depending-its-date/161993/6 "2009-03-05T08:33:33Z")

</div>

What I do not see is how to build those ‘date-groups’ because what I  
have now is only @events = Event.find(:all, :order =\> ‘date’)

In the view I do:

\<%= for event in @events %\>  
[…]

bill walton wrote:

> CSS. Wrap each date-group in a
> 
> and style it with  
> a top/bottom margin to get the spacing you’re looking for.
