Lets say im saving an array into my model. Is there any way to add an attribute to it?
I am running Property.create(property_params) to save the instances of the array into my model
Is there anyway to append an extra attribute to property_params that is not passed in the json? Lets say i want to pass a global variable currentuserid set in create method into .create and save it to the attribute in the model user_id along with property_params?
I tried using .merge on property_params but it didnt work. I guess i need to pass it into the array?
Is this possible?
def create
currentuserid = 4
property_items = PropertyItem.create(property_params)
end
private
def property_params
params.permit(property: [:houses, :id, :father, :mother, :height, :children, :pets]).require(:property)
end
This is my json below:
"property":[
{
"houses":"1",
"id":"5",
"father":"Jerry",
"mother":"Tanya",
"height":281,
"children":2,
"pets":24
},
{
"houses":"3",
"id":"5",
"father":"Rob",
"mother":"Anne",
"height":726,
"children":1,
"pets":55
}
]
}