RESTful and pretty URLs

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!

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

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

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.

On 1/8/07, Carl J. [email protected] 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

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.