How to get alternative info from a routing namespace in rails?
Imagine you are working on a f,acebook(to skip the g,f,w) like site, and you need some routes like:
www.mydomain.com/ihome/jim/posts
www.mydo开发者_StackOverflow社区main.com/ihome/jim/post/3
www.mydomain.com/ihome/jim/posts/3/edit
.
Then how to set the routes to get the 'jim' part? I know I can use the following if there is no account part:
namespace :ihome do
resources :posts
end
A quick (untested) answer is : use the scope, it will give you a params[:user]
namespace :ihome do
scope ":user" do
resources :posts
end
end
Have a look at the docs here : http://guides.rubyonrails.org/routing.html#defining-defaults
精彩评论