Validation that works in the controller


#1

Hi,

Is there a way of validating input inside the controller? or an
equivalent to
ActiveRecord::Validations::ClassMethods.validates_presence_of ?

Cheers,

– Colin


#2

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


#3

On 12/19/05, Chris H. removed_email_address@domain.invalid wrote:

http://rails.rubyonrails.com/classes/ActiveRecord/Validations.html

On 12/19/05, Colin JN Breame <removed_email_address@domain.invalid > wrote:

Hi,

Is there a way of validating input inside the controller? or an equivalent
to

ActiveRecord::Validations::ClassMethods.validates_presence_of

I 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