开发者

How to get alternative info from a routing namespace in rails?

开发者 https://www.devze.com 2023-04-09 23:27 出处:网络
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

Imagine you are working on a f,acebook(to skip the g,f,w) like site, and you need some routes like:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消