Strong Params in Rails model

69 Views Asked by At

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?

1

There are 1 best solutions below

0
On

The problem was that the page from where I was calling this API sent params instead of peoples_friend. So, I did this :

params.permit(:name, :age)