Access child validation attachment_fu
I'm using attachment_fu for image uploading. I have a class Photo and class Image, Photo has_one :image.
The reason I'm doing this is because my photos are sortable with a position attribute, and if I just have this position attribute on the image, it makes a db call for each image AND thumbnail that I create with attachment_fu. It's a little db intesive, so I just maintain the position in the Photo class and reference Image.
The only problem is, the validations specified in my has_attachment statement in Image, don't actually work when I call Photo save. Here's my code:
If, say, the image is over the max-size or there is no file chosen, it still saves the photo, but has image -> nil
@photo = Photo.new
@image = Image.new(:uploaded_data => params[:photo][:file])
@photo.image = @image
if @photo.save redirect_to @photo
How can I access the validators of the child class Image to test this when saving the photo.
I tried saying
, but this seems to ignore the validations, larger images work and if no files is specified, image is nil
if @photo.save && @image.save