2015-12-25 66 views
2

使用Rails 4,设计,简单的形式。读了很多关于这个,但肯定没有足够的经验。我做了RegistrationController,自定义视图也存在。 有了这个,我有密码确认没有问题,但我所有的PARAMS是不允许的:在没有密码确认的情况下设计更新附加属性。

def update_resource(resource, params) 
    resource.update_without_password(params) 
end 

据我所知,这应该是决定,但对我没有任何影响:

def configure_account_update_params 
    devise_parameter_sanitizer.for(:account_update) do |u| 
     u.permit(:username, :first_name, :last_name, :price_plan_id, :email_notify, :msg_notify, 
       :email, :password, :password_confirmation, :current_password) 
    end 
    end 

也许有人能写出关于它的整个概念性答案吗?

+0

你在注册控制器中放了before_filter:configure_permitted_pa​​rameters吗? –

+0

@DileepNandanam这个任务迭代太多了。你是对的,在这里我忘了说。非常感谢,一切正常。在我的情况下,回调函数是'before_filter:configure_account_update_params,只有:[:update]'随意写答案,我会接受它。 – nobilik

回答

1

启用那些谁错过了回调。

class ApplicationController < ActionController::Base 
    before_action :configure_account_update_params, if: :devise_controller? 
0

在我的模型,设计被赋予我已经添加了这些方法:

def skip_devise 
    @skip = true 
end 

def password_required? 
    [email protected]? ? false : super 
end 

def email_required? 
    [email protected]? ? false : true 
end 

您的模型将覆盖设计的password_required?email_required?方法。

当我想要我的模型跳过这些验证我刚刚运行此:

my_model.skip_devise 
my_model.save! 
相关问题