我使用的是Ruby on Rails 3.2.9。在我的应用程序中,我想处理多个"东西"的登录和注销功能,因为除了经典用户之外,"其他东西"可以登录和注销。我想实现一个"专用"的REST-ful sessions_controller
为每一个东西,可以验证,也许通过在config/routes.rb
文件中做下面的东西:
# Before:
# resources :users
# resources :other_things
# After:
resources :users do
resource :sessions, :only => [:new, :create, :destroy], :controller => 'users/sessions'
end
resources :other_things do
resource :sessions, :only => [:new, :create, :destroy], :controller => 'other_things/sessions'
end
使用上面的代码,我试图"分离"/"命名空间"身份验证关注用户和其他事情。但是,与上述代码不同的是,我希望按照以下方式匹配登录和注销url:
localhost/users/sign_in
localhost/users/sign_out
localhost/other_things/sign_in
localhost/other_things/sign_out
我应该怎么做?你有什么建议?
也许是这个?由于路线很少,我就不花时间多打扫了。
resources :users do
get :sign_in => 'users/sessions#new'
post :sign_in => 'users/sessions#create'
delete :sign_out => 'users/sessions#destroy'
end
resources :other_things do
get :sign_in => 'other_things/sessions#new'
post :sign_in => 'other_things/sessions#create'
delete :sign_out => 'other_things/sessions#destroy'
end