How to validate with validates_associated

Hi , i am facing strange problem i want to validate two models through

class Cpanel::Banner < ActiveRecord::Base

has_one :bannerimage
validates_associated :bannerimage
validates_presence_of :title
validates_uniqueness_of :title

class Cpanel::Bannerimage < ActiveRecord::Base

belongs_to :banner

has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 10.megabytes,
:resize_to => ‘320x200>’,
:processor => ‘MiniMagick’


Here are two models , i am not getting only banner model validation but
not for bannerimage model .

Thanks .

Ok ! this should work !

But if not go for

In your banner model !

def validate
errors.add_to_base “Where is file!” if

Otherwise use Activerecord callbacks !

Glad to help !

def validate
errors.add_to_base “Where is file!” if

This is always true though i am attaching file ! I think i should use
call back or
proper use of validates_associated…

Please help !

Thanks !

Is any one have idea !

Am 09.07.2009 um 15:41 schrieb Ruby on Rails:

Please refrain from bumping so often, at the very best, it will annoy
people who would be willing to help you…


Sorry , for that but i am seeking for help regarding

I haven’t used validates_associated before, but if you read the
documentation (, it says the following:

NOTE: This validation will not fail if the association hasn‘t been
assigned. If you want to ensure that the association is both present
and guaranteed to be valid, you also need to use

Are you sure a bannerimage has been assigned to your banner object?

On Jul 9, 8:59 pm, Ruby on Rails [email protected]

Thanks ,

I have banner_id in bannerimage table .

It would help if you would show test code which demonstrates the failing