Forum: Ruby on Rails RESTful and pretty URLs

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.
Carl J. (Guest)
on 2007-01-08 05:26
I've switched over to RESTful behavior on my site I am working on.

A URL like this works fine:

/make/1/model/2/year/1995

Assuming that make.find(1).name is 'Ford' and model.find(2).name is
'Taurus' (year is obvious) is it possible to be RESTful and still have
pretty URLs? Such as:

/vehicle/Ford/Taurus/1995

Of course this works in the old scheme with something like:

map.vehicle vehicle/:make_name/:model_name/:year_id, :controller =>
'vehicle', :action => 'show'

Thanks!
Russell N. (Guest)
on 2007-01-08 14:37
(Received via mailing list)
Part of the solution [the easy part] would be to implement to_param in
your
models to yield the product name/make rather than the id. I'm just not
sure
how to eliminate the words make, model, and year. Maybe someone else
will
respond to that. I'm a RESTful noob myself.

RSL
Carl J. (Guest)
on 2007-01-08 20:38
I can live with the controller words in the URL if I have to.

I was not aware of to_param. The docs don't seem to really talk about
to_param in this way and from reading a blog post or two it would seem
to be "black magic". Not sure I want to go there...

As far as I can tell the URL naming flexibility is just not available
when RESTful, like it is with classic routing. That's unfortunate.


Russell N. wrote:
> Part of the solution [the easy part] would be to implement to_param in
> your
> models to yield the product name/make rather than the id. I'm just not
> sure
> how to eliminate the words make, model, and year. Maybe someone else
> will
> respond to that. I'm a RESTful noob myself.
>
> RSL
kris (Guest)
on 2007-01-08 20:55
(Received via mailing list)
If you want an idea on how to use to_param, check out the
acts_as_sluggable.
I believe the peepcode RESTful movie also goes over using to_param, but
I
could be incorrect.
Pat M. (Guest)
on 2007-01-09 22:26
(Received via mailing list)
On 1/8/07, Carl J. <removed_email_address@domain.invalid> wrote:
>
> I can live with the controller words in the URL if I have to.
>
> I was not aware of to_param. The docs don't seem to really talk about
> to_param in this way and from reading a blog post or two it would seem
> to be "black magic". Not sure I want to go there...
>
> As far as I can tell the URL naming flexibility is just not available
> when RESTful, like it is with classic routing. That's unfortunate.

Of course it is flexible.  REST is about creating resources and making
them usable with the HTTP verbs.  That's really all there is to it.
Using map.resources doesn't make your app RESTful, and not using
map.resources doesn't preclude you from making your app RESTful.  It
just automates a lot of the routing for you so it's easier to get
where you want to be.

Pat
Carl J. (Guest)
on 2007-01-09 23:01
> Of course it is flexible.  REST is about creating resources and making
> them usable with the HTTP verbs.  That's really all there is to it.

Sorry, I should clarify. REST is flexible. I could create my own RESTful
routes and links, of course.

map.resources is not flexible in one area - it only accepts :id. As far
as I can tell.
This topic is locked and can not be replied to.