ActiveModel :: ForbiddenAttributesError in PasswordResetsController update #

I saw episode 274 of Ryan railcasts. I use rails 4 and ran into one problem.

In password_resets_controller.rb

elsif @user.update_attributes(params[:user]) 
Console

IN shows

 ActiveModel::ForbiddenAttributesError in PasswordResetsController#update 

when i changed update_attributes to update_attribute it shows

 wrong number of arguments (1 for 2) 

params[:user] shows two values ​​for password and password_confirmation , but I use password on my login page

I do not know how to solve this problem.

+6
source share
2 answers

This is due to the Strong Options feature in Rails 4. It will be enhanced if forbidden attributes are used for bulk assignment.

You must enable the attributes of your controller. Like this

 @user.update_attributes(params.require(:user).permit(:password, :password_confirmation)) 
+29
source

Had an identical problem - getting the same error message when trying to make any changes to any of my resources from Active Admin. Strong parameters were correctly entered into the model controller, but only after reviewing the documentation I realized that I needed to include the model attributes that will be added to the model in the / admin / your _model.rb application. As soon as I did this, everything worked correctly from Active Admin.

application / admin / your_model.rb

 ActiveAdmin.register Your_model do permit_params :attribute_1, :attribute_2, :attribute_3, :etc, :etc end 

This worked on my local server. After pushing the changes to git and deploying to VPS, it worked there too. Make sure you restart the application. In one case, I had to restart my instance. Hope this helps someone.

0
source

Source: https://habr.com/ru/post/949111/


All Articles