# Display only by date selected

**URL:** <https://www.ruby-forum.com/t/display-only-by-date-selected/189328>\
**Category:** Rails\
**Created:** [May 28, 2010, 8:10pm UTC](https://www.ruby-forum.com/t/display-only-by-date-selected/189328 "2010-05-28T20:10:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hazmatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@hazmatt](https://www.ruby-forum.com/u/hazmatt)\
**Post date:** [May 28, 2010, 8:10pm UTC](https://www.ruby-forum.com/t/display-only-by-date-selected/189328/1 "2010-05-28T20:10:53Z")

</div>

I have the following code:

* * *

### Today's Activity

* * *

 \<% @orders.reverse.each do |order| %\> \<%= link\_to\_remote( "#{order.id} &nbsp &nbsp &nbsp #{order.name}" , :url =\> {:controller =\> 'orders', :action =\> 'show', :id =\> order.id }, :update =\> "order\_div", :method =\> 'get' ) %\>

\<% end %\>

* * *

This code works great. Does exactly what I need. I’m displaying the  
order id and customer name on the order. I have the newest one on top by  
using the reverse method.

What I need to be able to do is where it has “Today’s” in the h3 tag, I  
want to created a dropdown that people can select: Today, Yesterday, One  
Week, 2 Weeks, One Month, All, etc.

I don’t know what kind of logic I’ll need to make sure that the only  
orders showing are those connected to one of those actions in the  
dropdown list. Only that I’ll need to call the create date field in the  
db.

I’ve gone through a few ruby on rails books and a ruby book. This is the  
my first personal project that I’ve worked on, so I’m not sure how to  
complete this. Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![hazmatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@hazmatt](https://www.ruby-forum.com/u/hazmatt)\
**Post date:** [May 29, 2010, 3:10am UTC](https://www.ruby-forum.com/t/display-only-by-date-selected/189328/2 "2010-05-29T03:10:01Z")

</div>

Matt R. wrote:

> I have the following code:
> 
> * * *
> 
> ### Today's Activity
> 
> * * *
> 
> \<% @orders.reverse.each do |order| %\> \<%= link\_to\_remote( "#{order.id} &nbsp &nbsp &nbsp #{order.name}" , :url =\> {:controller =\> 'orders', :action =\> 'show', :id =\> order.id }, :update =\> "order\_div", :method =\> 'get' ) %\>
> 
> \<% end %\>
> 
> * * *
> 
> This code works great. Does exactly what I need. I’m displaying the  
> order id and customer name on the order. I have the newest one on top by  
> using the reverse method.
> 
> What I need to be able to do is where it has “Today’s” in the h3 tag, I  
> want to created a dropdown that people can select: Today, Yesterday, One  
> Week, 2 Weeks, One Month, All, etc.
> 
> I don’t know what kind of logic I’ll need to make sure that the only  
> orders showing are those connected to one of those actions in the  
> dropdown list. Only that I’ll need to call the create date field in the  
> db.
> 
> I’ve gone through a few ruby on rails books and a ruby book. This is the  
> my first personal project that I’ve worked on, so I’m not sure how to  
> complete this. Any help would be appreciated.

Seems like pretty elementary logic…  
For populating the droplist on the form, you just need a set of items  
with a defined coding scheme (0 = today, 1 = 1 week, 2 = 2 weeks, 3 = 1  
month, 4 = 1 year, 5 = all, or some such).

In the controller interpreting the link\_to\_remote, it just had to  
determine:  
What’s today?  
That tells you the range for yesterday  
That tells you the range for today through today - 6 days  
That tells you the range for today through today - 13 days  
etc  
etc

Peruse the Pickaxe book… you _do_ have one don’t you? If not, for  
shame…  
(just joking, you should be able to find the appropriate ruby references  
on the web).

---

<div class="post-metadata">

**Author:** ![hazmatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@hazmatt](https://www.ruby-forum.com/u/hazmatt)\
**Post date:** [May 29, 2010, 4:47pm UTC](https://www.ruby-forum.com/t/display-only-by-date-selected/189328/3 "2010-05-29T16:47:41Z")

</div>

Ar Chron wrote:

> Seems like pretty elementary logic…  
> For populating the droplist on the form, you just need a set of items  
> with a defined coding scheme (0 = today, 1 = 1 week, 2 = 2 weeks, 3 = 1  
> month, 4 = 1 year, 5 = all, or some such).
> 
> In the controller interpreting the link\_to\_remote, it just had to  
> determine:  
> What’s today?  
> That tells you the range for yesterday  
> That tells you the range for today through today - 6 days  
> That tells you the range for today through today - 13 days  
> etc  
> etc
> 
> Peruse the Pickaxe book… you _do_ have one don’t you? If not, for  
> shame…  
> (just joking, you should be able to find the appropriate ruby references  
> on the web).

Perfect! Thank you.

I know, elementary stuff here. I’m still trying to figure the ruby part  
of things out. I’ve read a couple of Rails book and only a small Ruby  
book. The Rails books teach minimal Ruby, so I know I need to go back  
through all of that. Thanks for the tip on the pickaxe book! I’ll take a  
look into that one. Thanks again.
