我认为这样做很好...... Rails中的路由是灵活的原因(允许这样的情况)。
不过,我会改变你的路线更是这样为了正确命名您的路径助手:
scope :admin, :as => :admin, :constraints => { :subdomain => "admin" } do
resources :photos
end
scope '/mystuff', :as => :mystuff, :constraints => { :subdomain => "www" } do
resources :photos
end
,这将给你:
admin_photos GET /photos(.:format) {:subdomain=>"admin", :action=>"index", :controller=>"photos"}
POST /photos(.:format) {:subdomain=>"admin", :action=>"create", :controller=>"photos"}
new_admin_photo GET /photos/new(.:format) {:subdomain=>"admin", :action=>"new", :controller=>"photos"}
edit_admin_photo GET /photos/:id/edit(.:format) {:subdomain=>"admin", :action=>"edit", :controller=>"photos"}
admin_photo GET /photos/:id(.:format) {:subdomain=>"admin", :action=>"show", :controller=>"photos"}
PUT /photos/:id(.:format) {:subdomain=>"admin", :action=>"update", :controller=>"photos"}
DELETE /photos/:id(.:format) {:subdomain=>"admin", :action=>"destroy", :controller=>"photos"}
mystuff_photos GET /mystuff/photos(.:format) {:subdomain=>"www", :action=>"index", :controller=>"photos"}
POST /mystuff/photos(.:format) {:subdomain=>"www", :action=>"create", :controller=>"photos"}
new_mystuff_photo GET /mystuff/photos/new(.:format) {:subdomain=>"www", :action=>"new", :controller=>"photos"}
edit_mystuff_photo GET /mystuff/photos/:id/edit(.:format) {:subdomain=>"www", :action=>"edit", :controller=>"photos"}
mystuff_photo GET /mystuff/photos/:id(.:format) {:subdomain=>"www", :action=>"show", :controller=>"photos"}
PUT /mystuff/photos/:id(.:format) {:subdomain=>"www", :action=>"update", :controller=>"photos"}
DELETE /mystuff/photos/:id(.:format) {:subdomain=>"www", :action=>"destroy", :controller=>"photos"}