I am using Ruby on Rails 3 and I would like to redirect all requests made to a resource (URL) to another resource.
I have the following resources:
<My_app_name>::Application.routes.draw do
resources :users
namespace :users do
resources :user_admins
end
end
What I would like to do is to redirect all requests made to <my_app_name>/users/user_admins/<id>
to <my_web_site_name>/users/<id>
. How can I do that?
Note: I am using a Single Table Inheritance approach, so that the <id>
value will don't change behaviours. That is, the <id>
value will be automatically handled from the RoR framework and it will refer to the same resource for both when the URL is <my_app_name>/users/user_admins/<id>
or <my_w开发者_JS百科eb_site_name>/users/<id>
.
You may want to avoid the use of a namespace, and play it like that :
scope "users" do
resources "user_admins", :controller => "users"
end
You'll get those routes :
user_admins GET /users/user_admins(.:format) {:action=>"index", :controller=>"users"}
POST /users/user_admins(.:format) {:action=>"create", :controller=>"users"}
new_user_admin GET /users/user_admins/new(.:format) {:action=>"new", :controller=>"users"}
edit_user_admin GET /users/user_admins/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user_admin GET /users/user_admins/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/user_admins/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/user_admins/:id(.:format) {:action=>"destroy", :controller=>"users"}
Try this in your routes.rb:
match 'users/user_admins/:id' => 'users#show'
精彩评论