Forum: Ruby on Rails REST, routes and algorithms

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9ceeb190da20a2917644da86dbcd2322?d=identicon&s=25 Tim Conner (plump)
on 2008-10-27 11:32
I'm reading the book 'RESTful web services' and in the discussion on
exposing algorithmic resources it says the following:

"
Most web applications don’t store much state in path variables: they use
query variables instead. You may have seen URIs like this:
• http://www.example.com/articles?start=20061201&end...

Those URIs would look better without the query variables:
• http://www.example.com/articles/20061201-20071201
"

What is the Rails way for exposing algorithmic resources?  Is it via the
first URL in the example or the second?  If it is the second, please can
you give me some guidance on how to achieve this.
Thanks
Ce05eb89ec30c2b4be7efba010555a7c?d=identicon&s=25 irfani YangBaikHati (Guest)
on 2008-10-27 13:30
(Received via mailing list)
start, finish = "20061201-20071201".split('-')

"end" is reserved keyword

Tim Conner wrote:
> "
>
> What is the Rails way for exposing algorithmic resources?  Is it via the
> first URL in the example or the second?  If it is the second, please can
> you give me some guidance on how to achieve this.
> Thanks
>


--
irfani

http://irfani.web.id
Y! irfani_s
70ca58d0e0e0eabbdb74d177417d09d7?d=identicon&s=25 August Lilleaas (leethal)
on 2008-10-27 15:07
> Those URIs would look better without the query variables:
> • http://www.example.com/articles/20061201-20071201
> "
>
> What is the Rails way for exposing algorithmic resources?  Is it via the
> first URL in the example or the second?  If it is the second, please can
> you give me some guidance on how to achieve this.
> Thanks

Rails conventions says that /articles/20061201-20071201 finds the
article with the id '20061201-20071201'. Anything other than that would
be unconventional.

There are of course conventions to breaking the conventions, though ; )
Personally, I'd do something like map.article_range '/articles/:range',
:action => 'range', :requirements => {:range => /(d+)\-(d+)/}. In the
'range' action, I'd do what YangBaikHati suggests above. start, finish =
params[:range].split('-').
This topic is locked and can not be replied to.