Hi, Is there a way of validating input inside the controller? or an equivalent to ActiveRecord::Validations::ClassMethods.validates_presence_of ? Cheers, -- Colin
just override the validate method class Foo < ActiveRecord::Base def validate errors.add(:name, "is blank") if name.nil? or name == "" # other validations end end then you can call @user.valid? at any time http://rails.rubyonrails.com/classes/ActiveRecord/Validations.html On 12/19/05, Colin JN Breame <colin-8viq6m4SR0+sTnJN9+BGXg@public.gmane.org> wrote:> > Hi, > > Is there a way of validating input inside the controller? or an equivalent > to > ActiveRecord::Validations::ClassMethods.validates_presence_of ? > > Cheers, > > -- Colin > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 12/19/05, Chris Hall <christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> just override the validate method > > class Foo < ActiveRecord::Base > def validate > errors.add(:name, "is blank") if name.nil? or name == "" > # other validations > end > end > > then you can call @user.valid? at any time > > http://rails.rubyonrails.com/classes/ActiveRecord/Validations.html > > > On 12/19/05, Colin JN Breame <colin-8viq6m4SR0+sTnJN9+BGXg@public.gmane.org > wrote: > > Hi, > > > > Is there a way of validating input inside the controller? or an equivalent > to > > > ActiveRecord::Validations::ClassMethods.validates_presence_ofI have a Rails Weenie tip for validating non-model data. It basically creates a table-less model you can use for a form: http://rails.techno-weenie.net/tip/2005/11/19/validate_your_forms_with_a_table_less_model -- rick http://techno-weenie.net