I have this code in my application_controller.rb

before_filter :update_sanitized_params, if: :devise_controller?
before_filter :store_location
protect_from_forgery with: :exception
def update_sanitized_params
    devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:email, :password, :password_confirmation, :role)}
    devise_parameter_sanitizer.for(:sign_in) {|u| u.permit(:email, :password) }
end

but I still have validation errors from devise

Email can't be blank
Password can't be blank
Password can't be blank
Role is not included in the list

Devise was working fine few days ago I don't know what messed up with it I have added active_admin may be this created conflicts any help please??

有帮助吗?

解决方案 2

I have solved the Problem by adding this line in user.rb

attr_accessible :email, :password, :role

and this works with gem " protected_attributes"

其他提示

Assuming that you are getting the validation errors while updating a User record.

def update_sanitized_params
    devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:email, :password, :password_confirmation, :role)}
    devise_parameter_sanitizer.for(:sign_in) {|u| u.permit(:email, :password) }
    ## Permit the attributes for account_update
    devise_parameter_sanitizer.for(:account_update) {|u| u.permit(:email, :password, :password_confirmation, :role) }
end

You need to permit the attributes explicitly which you would like to be updated by specifying devise_parameter_sanitizer.for(:account_update) else they would not be passed to users table for updating.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top