Updated:
I have a link_to set up for deleting an object that is a nested resource. Prior to destroy, I have a method that checks for the instance of that object based on object_params, but the params sent keep raising undefined method 'permit' for "asdfsadf":String
when it tries to reference the object_params
.
Button:
<%= link_to content_tag('button', '', class: 'btn fa fa-trash-o focus-delete-button'), parent_object_path( :parent_id => focus.z_kf_parent, :id => focus.id, :object => focus), data: {confirm: "Are you sure you want to delete '#{focus.name}'"}, method: :delete %>
Params:
{"_method"=>"delete",
"authenticity_token"=>"gmlVYHy230Y1lQY=",
"object"=>"6c1367b1-1d63-4545-bbdb-b8ac9bd39422",
"action"=>"destroy",
"controller"=>"objects",
"parent_id"=>"FA100073-4A0C-4EE0-8FB1-3EC39C61AD39",
"id"=>"5-bbdb-b8ac9"}
object_params:
def object_params
params.require(:set_list).permit(:id, :photographer, :digital_tech, :photo_production, :stylist, :stylist_assistant, :hair_makeup, :photographer_assistant, :name, :t_start, :t_finish, :z_kf_parent)
end
Method:
def set_object
binding.pry
@object = Object.(object_id: object_params[:id]).first
end
Am I not setting the parameters right in the link_to
?
Your object_params
method is requiring there to be a param called set_list
. There is no such parameter in your params
.
This will work for you:
def set_object
binding.pry
@object = Object.where(object_id: params[:id]).first
end
You don't need to wrap a params[:id]
lookup through a permit
as you're not mass-assigning anything.