我有以下路线
constraints :subdomain => "brands" do
scope :module => "brands", :as => "brands" do
devise_for :members
# devise_for :users, controllers: {
# sessions: 'users/sessions'
# }
end
end
当我转到http://brands.lvh.me:3000/members/sign_up
时,我收到以下错误
/ members / sign_up
中的ActionController :: RoutingError未初始化的常量品牌:: RegistrationsController应用程序 框架所有框架
ActionDispatch::Routing::RouteSet::Dispatcher#controller actionpack (4.2.5.2) lib/action_dispatch/routing/route_set.rb, line 63
注册控制器 - `app / controllers / brands / members / registrations_controller.rb
class Brands::Members::RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
# GET /resource/sign_up
# def new
# super
# end
# POST /resource
# def create
# super
# end
# GET /resource/edit
# def edit
# super
# end
# PUT /resource
# def update
# super
# end
# DELETE /resource
# def destroy
# super
# end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params
# devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
# end
# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
# end
# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
# end
# The path used after sign up for inactive accounts.
# def after_inactive_sign_up_path_for(resource)
# super(resource)
# end
end
答案 0 :(得分:1)
评论中的回答:
创建一个控制器来覆盖设计一个。添加任何特定的需求或从Devise控制器继承。
然后在您的路线中,您可以告诉设计使用您刚设置的控制器:
devise_for :members, controllers: {:sessions => "your_scope/sessions"}
Devise doc (see section about configuring controllers and routes)
上述代码中的“your_scope”部分与使用特定范围的问题有关。
想法:设置必须丢失子域和范围事物,而不是确定控制器应该在哪个和哪里。所以,如果我是真的,你甚至可以跳过自定义控制器部分,并告诉Devise使用它自己的默认控制器。简而言之,告诉devise忘记范围并使用经典的默认机制。