SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    Code:
    @photo = Photo.new  
    @image = Image.new(:uploaded_data => params[:photo][:file])    
    @photo.image = @image         
    if @photo.save redirect_to @photo
    If, say, the image is over the max-size or there is no file chosen, it still saves the photo, but has image -> nil

    How can I access the validators of the child class Image to test this when saving the photo.
    I tried saying
    Code:
    if @photo.save && @image.save
    , but this seems to ignore the validations, larger images work and if no files is specified, image is nil

  2. #2
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i can't believe a solution wasn't posted for this before. I just found validates_associated. Calls all the validations of the class you reference.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •