我在form_for
check_box_tag "files_to_delete[]", :attach.id
允许参数:
params.require(:post).permit( ... , :files_to_delete => [])
我的模型中有before_action :some_method
,我希望能够访问files_to_delete
:
def some_method
files_to_delete.each do |attach|
attach.clear
end
end
但我明白了:
undefined local variable or method `files_to_delete' for #<Post:0x007f5c4cb51ad0>
答案 0 :(得分:1)
您的模型需要files_to_delete
的setter和getter。将以下行添加到模型中:
attr_accessor :files_to_delete