Src
Src

Reputation: 5502

Custom form_for field accessible in model

I have custom field in form_for

check_box_tag "files_to_delete[]", :attach.id

Permitted params:

params.require(:post).permit( ... , :files_to_delete => [])

I have before_action :some_method in my model, in which i want to have access to the files_to_delete:

def some_method
  files_to_delete.each do |attach|
    attach.clear
  end
end

But i get:

undefined local variable or method `files_to_delete' for #<Post:0x007f5c4cb51ad0>

Upvotes: 0

Views: 37

Answers (1)

spickermann
spickermann

Reputation: 107097

Your model needs a setter and getter for files_to_delete. Add the following line to your model:

attr_accessor :files_to_delete

Upvotes: 1

Related Questions