Hi , i am facing strange problem i want to validate two models through
validates_associated,
class Cpanel::Banner < ActiveRecord::Base
has_one :bannerimage
validates_associated :bannerimage
validates_presence_of :title
validates_uniqueness_of :title
end
class Cpanel::Bannerimage < ActiveRecord::Base
belongs_to :banner
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 10.megabytes,
:min_size=>250.bytes,
:resize_to => ''320x200>'',
:processor => ''MiniMagick''
validates_as_attachment
end
Here are two models , i am not getting only banner model validation but
not for bannerimage model .
Thanks .
--
Posted via http://www.ruby-forum.com/.
Ok ! this should work !
But if not go for
In your banner model !
def validate
errors.add_to_base "Where is file!" if
Bannerimage.find(self.id).blank?
end
Otherwise use Activerecord callbacks !
Glad to help !
--
Posted via http://www.ruby-forum.com/.
def validate errors.add_to_base "Where is file!" if Bannerimage.find(self.id).blank? end 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 ! -- Posted via http://www.ruby-forum.com/.
Is any one have idea ! -- Posted via http://www.ruby-forum.com/.
................ -- Posted via http://www.ruby-forum.com/.
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... Felix
Sorry , for that but i am seeking for help regarding validates_associated ! -- Posted via http://www.ruby-forum.com/.
I haven''t used validates_associated before, but if you read the documentation (api.rubyonrails.org), 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 validates_presence_of. Are you sure a bannerimage has been assigned to your banner object? On Jul 9, 8:59 pm, Ruby on Rails <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Sorry , for that but i am seeking for help regarding > validates_associated > ! > -- > Posted viahttp://www.ruby-forum.com/.
Thanks , I have banner_id in bannerimage table . -- Posted via http://www.ruby-forum.com/.