I’m looking to generate a link that has a prefix attached to the named route itself. Something like this to display the path “/old/recipes”:
recipes_path(:prefix => "old/") # the correct way should show "/old/recipes"
I don’t want to touch the routes.rb file, but modify the named route with the prefix attached. Is that possible and how would you do it correctly?
EDIT: I’m using Rails 3. The reason for adding the optional prefix is I want to use the normal recipes_path as well. So I want to use both “/recipes” and “/old/recipes”.
You’re going to run into a lot of pain if you don’t want to touch the routes file, mainly because that’s what Rails is going to reference when it tries to figure out where your route goes. I don’t know of another way to do that, so here’s the config/routes.rb code when you’re convinced it’s a good idea:
Now when you route to
recipes_pathit will go to/old/recipes, although this may not be what you’re after. If that’s the case, then you may want to chuck theasoption on the end of thisscope:In which case, this route would now be
old_recipes_path, still routing to/old/recipes.