On Apr 27, 2:04 pm, Kevin Monceaux <Ke...@RawFedDogs.net> wrote:
>
> to be the index with a list of recipes. For viewing a single recipe,
> using a slug, it would make more sense for the route to be something
> like:
>
> Recipe/Beef-Brisket
>
> instead of:
>
> Recipes/Beef-Brisket
>
> Is there a way to configure RESTful routes to use plural collection
> routes and singular member routes? For the moment I have all of my
> routes mapped separately via match statements but I'd like to find an
> easier way, especially if/when I get to a point where nested resources
> would come in handy.
I didn't see anyone in this thread answer your actual, original
question on here so I figured I'd chime in. I'm not familiar with the
Rails 3 routes syntax yet, but I think in Rails 2.x this should be as
simple as:
map.resources :recipes
map.connect 'Recipe/:id', :controller => 'recipe', :action => 'show'
That should tie the route you want into the conventional controller
method, which should allow both to exist in harmony, which means you
can use all the normal conventions for restful items from the
controller down; all this should do in effect is point your ~custom~
routing URL to the RESTful show action. Note that a few things I
haven't shown which you'll likely want are:
1) An override on def self.find for the Recipe model to search by ID
or by permalink
2) An override of to_param to output the name instead of ID for
permalinking.
3) Possibly a helper to generate your desired URLs in your views, such
as def permalink_recipe_path(name) ...; I haven't tried it but you
might be able to name the route above to accomplish this, something
like
map.permalink_recipe 'Recipe/:id', :controller => 'recipe', :action
=> 'show'
But I'm not sure how exactly that works with passing in a parameter.
I'd start with the URL mapping, and see when the normal redirects and
what not get you to a URL you don't like.
\Peter
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment