我正在使用Devise 3运行Rails 4应用程序,我想为Devise设置一组辅助路由。我有一个Portal
模型,它代表一个独特的子站点,但共享相同的核心用户群。我希望能够将用户发送到/portals/:portal_id/users/sign_in
之类的路由,并使其行为与Devise使用/users/sign_in
创建的默认devise_for :users
路由的行为相同。我怎么能这样做?
以下是我的路线:
MyApp::Application.routes.draw do
devise_for :users, :controllers => {:registrations => "registrations"}
root 'general#home'
resources :portals, controller: 'portals/general' do
member do
root 'portals/general#home'
end
end
end
我还有RegistrationsController
覆盖默认的Devise控制器,如下所示:
class Portals::RegistrationsController < RegistrationsController
layout 'portals/layouts/application'
def create
@portal = Portal.friendly.find(params[:id])
build_resource(sign_up_params)
resource_saved = resource.save
yield resource if block_given?
if resource_saved
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
redirect_to :back
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
# respond_with(resource, location: root_path)
flash[:notice] = resource.errors.full_messages.first
redirect_to root_portal_path(resource)
end
end
end