# Restful dates: from, to

**URL:** <https://www.ruby-forum.com/t/restful-dates-from-to/127746>\
**Category:** Rails\
**Created:** [January 31, 2008, 10:00pm UTC](https://www.ruby-forum.com/t/restful-dates-from-to/127746 "2008-01-31T22:00:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajaxrussia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ajaxrussia](https://www.ruby-forum.com/u/ajaxrussia)\
**Post date:** [January 31, 2008, 10:00pm UTC](https://www.ruby-forum.com/t/restful-dates-from-to/127746/1 "2008-01-31T22:00:39Z")

</div>

Hello,

I’m having trouble making my application restful. I want to show posts  
between 2 dates.

For example posts between march 2007 and may 2007. I don’t know how to  
represent this timespan a single resource because it has 2 parts: from  
and to. The url I’m looking for is something like this /from/  
01-03-2007/to/01-05-2007/posts

But that means that there are 3 resources here: “From” resource, “To”  
resource and “Posts”.

And nested routes would look something like this:

map.resources :from do |from|  
from.resources :to do |to|  
to.resources :posts  
end  
end

Is this solution ok, or there is some more elegant way of solving  
this?

Thanks

---

<div class="post-metadata">

**Author:** ![ajaxrussia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ajaxrussia](https://www.ruby-forum.com/u/ajaxrussia)\
**Post date:** [January 31, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/restful-dates-from-to/127746/2 "2008-01-31T22:32:28Z")

</div>

How about start date and timespan, so start-dates are the basis of  
your url and timespan is a parameter.  
Just a thought 🙂

---

<div class="post-metadata">

**Author:** ![ajaxrussia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ajaxrussia](https://www.ruby-forum.com/u/ajaxrussia)\
**Post date:** [February 1, 2008, 12:07am UTC](https://www.ruby-forum.com/t/restful-dates-from-to/127746/3 "2008-02-01T00:07:09Z")

</div>

You mean like /from/01-03-2007/posts?to=01-05-2007 ?

This is kind of ugly

---

<div class="post-metadata">

**Author:** ![ajaxrussia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ajaxrussia](https://www.ruby-forum.com/u/ajaxrussia)\
**Post date:** [February 1, 2008, 12:18am UTC](https://www.ruby-forum.com/t/restful-dates-from-to/127746/4 "2008-02-01T00:18:53Z")

</div>

Well maybe, but you can get rid of the from and have

posts/01-03-2007?to=01-05-2007

and if there is no ‘to’ you’d just get the posts on the day.

---

<div class="post-metadata">

**Author:** ![ajaxrussia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ajaxrussia](https://www.ruby-forum.com/u/ajaxrussia)\
**Post date:** [February 1, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/restful-dates-from-to/127746/5 "2008-02-01T23:31:29Z")

</div>

On Jan 31, 2008 3:59 PM, ajaxrussia [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Is this solution ok, or there is some more elegant way of solving  
> this?

I think that the most natural way would be simply:

/posts?from=01-03-2007&to=01-05-2007

This seems like a perfecly acceptable uri from a REST point of view,  
and your posts controller can simply look for params[:from], and  
params[:to] in the index action

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![ajaxrussia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@ajaxrussia](https://www.ruby-forum.com/u/ajaxrussia)\
**Post date:** [February 4, 2008, 6:23am UTC](https://www.ruby-forum.com/t/restful-dates-from-to/127746/6 "2008-02-04T06:23:33Z")

</div>

I too am looking for a good way to expose a date parameter in a url  
using restful routing…

I’d like to stay away from query string parameters (i.e. ?/&) in  
pursuit of cleaner urls without potential caching/search engine  
difficulties. For example, I like how Dopplr structures their urls  
quite a bit (probably using map.connect?):

[http://www.dopplr.com/traveller/adamjh/journal/2008/01/trips](http://www.dopplr.com/traveller/adamjh/journal/2008/01/trips)

… where 2008/01/trips are parameters used to scope journal results  
(2008/01 scopes the year/month, and trips filters the results to items  
of type ‘trip’)

Any ideas how I could achieve something similar with  
map.resources? :path\_prefix can enable the type of parameter passing  
I need, but prepending them onto the url doesn’t yield the same  
logical structure I’m looking for (i.e. ability for a visitor to chop  
a parameter off the url and find herself a level higher in the site’s  
information architecture).

Thanks,

- Adam
