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.
5e75f4b81923cd04a5c8fffa290be92e?d=identicon&s=25 Carl Johnson (carlivar)
on 2007-01-08 04: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!
70225136eacd3d870f64e03bff678655?d=identicon&s=25 Russell Norris (Guest)
on 2007-01-08 13: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
5e75f4b81923cd04a5c8fffa290be92e?d=identicon&s=25 Carl Johnson (carlivar)
on 2007-01-08 19: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 Norris 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
5a903f9189f9e232dead46eb6be1dd19?d=identicon&s=25 kris (Guest)
on 2007-01-08 19: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.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2007-01-09 21:26
(Received via mailing list)
On 1/8/07, Carl Johnson <rails-mailing-list@andreas-s.net> 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
5e75f4b81923cd04a5c8fffa290be92e?d=identicon&s=25 Carl Johnson (carlivar)
on 2007-01-09 22: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.