mardi 16 juin 2015

Strong Params in Rails model

I have a model Peoples::Friend and my friend.rb is :

attr_accessible :name, :age

I removed this line because of mass assignment vulnerability. I have this controller peoples_controller.rb

friend = Peoples::Friend.update_attributes(:name => "test", :age => 23)

I removed the above line and added the following lines :

friend = Peoples::Friend.update_attributes(peoples_friend_params)

and added this function :

def peoples_friend_params
    params.require(:peoples_friend).permit(:name, :age)
end

Now, when I run the API, it says ActionController::ParameterMissing (param is missing or the value is empty: peoples_friend)

What is wrong?

Aucun commentaire:

Enregistrer un commentaire