我创建了2个海关管理员来管理注册:
class RegistrationsController < Devise::RegistrationsController
protected
def update_resource(resource, params)
resource.update_without_password(params)
end
def after_sign_up_path_for(resource)
dashboard_path
end
结束
和该线程中的另一个类似: Rails multiple registration paths with Devise
class QuickstartsController < Devise::RegistrationsController
# GET /quickstarts/new
def new
# This block is passed to the super class implementation:
super do |resource|
@user = resource.build_profile
end
end
# POST /quickstarts
def create
super
end
protected
def update_resource(resource, params)
resource.update_without_password(params)
end
# Signs in a user on sign up. You can overwrite this method in your own
# RegistrationsController.
def sign_up(resource_name, resource)
@profile = Profile.new(user: resource)
sign_in(resource_name, resource)
if(@profile.save)
end
end
def after_sign_up_path_for(resource)
# FORCE SIGN_IN HERE ...?
end
def sign_up_params
params.require(:user)
.permit(
:fullname, :password, :email,
profile_attributes: [:user_id, :street, :postal_code,
:title, :summary, :city])
end
end
所以第一种方法是好的:sign_up之后,将创建用户,并且我会自动sign_in(我在/initializers/devise.rb中未注释此行): config.allow_unconfirmed_access_for = 2.天
但是QuickstartsController还要创建用户(一切正常),但是使用此自定义控制器进行sign_up之后,用户不会自动sign_in ?? 我的错在哪里?我尝试更改为强制sign_in进入此方法
def after_sign_up_path_for(resource)
# FORCE SIGN_IN HERE ...?
end
但是它不起作用...