#11 ✓invalid
Rizwan Reza

Weird Validation Error

Reported by Rizwan Reza | July 12th, 2007 @ 09:53 AM

I am using attachments in a model with some other data to pass along and I have validations running on them. The validations work on failing, but when the form is filled correctly, it shows:

Validation failed: Name can't be blank, Code can't be blank, Country can't be blank

It works if I don't have the attachment for my model in first place. Is it a bug?

This was also commented by by Jon on 23 May on Rick's blog.

Comments and changes to this ticket

  • Rick

    Rick July 12th, 2007 @ 09:53 AM

    • State changed from “new” to “invalid”

    That's your model failing, not attachment_fu. Though if you have thumbnails, those might be failing too. You'll have to use one of the callbacks to pull that info from the main attachment model. Or use a :if option on your validators:

    class Foo < AR::Base
      has_attachment ...
      validates_presence_of :foo, :if => { |r| r.parent_id.nil? }
    end
    
  • Liam Davison

    Liam Davison August 3rd, 2008 @ 04:29 AM

    • Tag set to bug, error, validation

    What do we do if it is the thumbnails which are causing the error? I.E this fails:

    class Photograph < ActiveRecord::Base

    belongs_to :meal

    has_attachment :content_type => :image,

    :storage => :file_system,

    :max_size => 1024.kilobytes,

    :resize_to => '640x480>',

    :thumbnails => { :thumb => '100x100>'},

    :processor => 'Rmagick'

    validates_as_attachment

    validates_presence_of :label

    end

    With the error "Label can't be blank"

    But this succeeds:

    class Photograph < ActiveRecord::Base

    belongs_to :meal

    has_attachment :content_type => :image,

    :storage => :file_system,

    :max_size => 1024.kilobytes,

    :resize_to => '640x480>',

    :processor => 'Rmagick'

    validates_as_attachment

    validates_presence_of :label

    end

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Pages