我正在尝试使用 Devise 实现 Wicked gem,因为我希望用户通过不同的步骤来完成他们的个人资料。我是一个完整的新手,所以如果你能给我一个关于可能是什么问题的建议,我将不胜感激。
我得到的错误就是这个错误,当我尝试从“个人”继续到“风格”步骤时它会显示出来。我想这是保存数据的问题:
NoMethodError in OnboardingController#update
undefined method `attributes' for nil:NilClass
**@user.attributes(user_params)**
这些是我的注册和入职控制器:
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
'/onboarding/personal'
end
def after_update_path_for(resource)
registration_steps_path
end
def new
super
end
def create
super
end
def update
super
end
def update_resource(resource, params)
if resource.encrypted_password.blank? # || params[:password].blank?
resource.email = params[:email] if params[:email]
if !params[:password].blank? && params[:password] == params[:password_confirmation]
logger.info "Updating password"
resource.password = params[:password]
resource.save
end
if resource.valid?
resource.update_without_password(params)
end
else
resource.update_with_password(params)
end
end
end
和
class OnboardingController < ApplicationController
include Wicked::Wizard
steps :personal, :stylefirst
def show
@user = current_user
render_wizard
end
def update
@user = current_user
@user.attributes(user_params)
render_wizard @user
end
end