I can't get this before_save
filter to work. My methods are pretty standard, I think. Images are uploaded via Paperclip.
before_save :remove_checked_attachments
def attachments
%w(banner footer logo accreditation)
end
private
def remove_checked_attachments
attachments.each do |a|
if "remove_#{a}".to_sym && !"#{a}_updated_at_changed?".to_sym
"#{a}".to_sym.destroy
end
end
end
The remove_...
params are passed, nothing's deleted though:
... "remove_banner"=>"1" ...
Any thoughts? Thanks.
Update
Even simplifying it to this doesn't work:
after_validation { banner.clear if remove_banner == '1' }
And "remove_banner"=>"1"
comes through in the params. The u.banner.clear
then u.banner.save
works fine in the console.