views:

26

answers:

1

Hi there,

I'm using Paperclip and accepts_nested_attributes for. I'm wondering what is the best way to discard photos (i.e. not save them in the db), if they have {model}_file_size == nil. This could be done using attribute_fu like in the example bellow, using the discard_if option. The Photo class uses Paperclip. However, I don't want to use attribute_fu.

class Stadium 
  has_many :photos, :as => :parent, :discard_if => proc { |upload| upload.photo_file_size.nil? } # discard_if does not work
  accepts_nested_attributes_for :photos
end

Many thanks.

A: 

Paperclip provides a validates_attachment_size validation which i think will achieve what your after, take a look at the readme http://github.com/thoughtbot/paperclip

also, this link may be of interest.

http://shiningthrough.co.uk/Dynamic-multiple-image-uploads-with-Ruby-on-Rails

Jon
Thank you. Not quite what I had in mind but solved my problem :)
cristian