1

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?

dgg
  • 333
  • 3
  • 11

2 Answers2

1

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.

tolgap
  • 9,629
  • 10
  • 51
  • 65
  • I tried this out and it creates the instance, but still manages to hit the `object_params` and error out. – dgg Oct 02 '15 at 21:04
  • 1
    I was being deceived! I restarted my server and it worked like a charm! Thanks much :) Also out of curiosity, if I were to maintain the `object_params`, would including `set_list` in the params solve it a different way? – dgg Oct 02 '15 at 21:11
  • Yes, but you definitely do not need something like object_params for a select query. You only need to permit attributes if youre going to do something like `Object.new object_params` so you control the attributes and no harmful attributes can be set by a user. – tolgap Oct 02 '15 at 21:32
0

It looks to me like you are attempting to use a plain hash to build an object where strong parameters are expected.

Use

@object = Object.where(object_params).first

rather than trying to push them inside a hash in the build method

Edit

It also appears that your link requires an update:

parent_object_path(set_list: {id: ..., etc})

since you code says it expects the set_list object.

** Previous edit was incorrect, sorry **

Phil
  • 2,797
  • 1
  • 24
  • 30
  • This still returned the same error, possibly because it is still looking for `object_params`? Also, is it possible that it is looking for a an object, but I am giving it a string? – dgg Oct 02 '15 at 21:02