Thursday, May 13, 2010

[Rails] Re: Routing - newbie question about shorting the url

This is possible but you will basically be setting up a rule like this

"whenever we get a url like /foo/bar then we want the category 'foo' and
the recipe 'bar'"

That might clash with the existing url schema on your site. If you want
to go for it though then set up your routes like this:

map.category_recipe ':category_name/:recipe_name', :controller =>
'recipes', :action => 'show', :conditions => {:method => :get}

Make sure you put it down the bottom, above the

map.connect ':controller/:action/:id'

section.

Now the url http://localhost/italian/special-pasta-sauce

should call the recipes controller, with params like {:recipe_name =>
"special-pasta-sauce", :category_name => "italian"}

And in your views you can say eg
category_recipe_path(category, recipe)

The above assumes that you've overriden to_param in Category and Recipe
to use the name of the object instead of it's id.

If you're using slus or something instead of name then you can
substitute appropriately.
--
Posted via http://www.ruby-forum.com/.

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate