Re: [Rails] Using validation helpers for custom validation
by Elliot Bowes other posts by this author
Sep 9 2005 8:19AM messages near this date
[Rails] Using validation helpers for custom validation
|
Re: [Rails] Using validation helpers for custom validation
Hi
Rails can handle that validation straight out of the box, and in one line too:
validates_length_of :variable, :within => 3..40, :allow_nil => true,
:on => :update
Regards
Elliot
On 09/09/05, Derek Haynes <derek.haynes@[...].com> wrote:
> I'd like to validate that the length of text is within a specified
> range, but only if the text is not nil.
>
> To do this, I'd like to setup a custom validation:
>
> def validate_on_update
> validate_within_range_if_not_nil
> end
>
> Where validate_within_range_if_not_nil would first check if the text
> is nil, and if not, then use the validation helper
> #validates_length_of.
>
> However, I don't know how to call this method from within a custom
> validation method. I tried:
>
> ActiveRecord::Validations::ClassMethods::validates_length_of
>
> But received a NoMethodError.
>
> Any ideas on implementing this type of validation?
> --
> Derek Haynes
> HighGroove Studios - http://www.highgroove.com
> Keeping it Simple.
> 404.593.4879
> _______________________________________________
> Rails mailing list
> Rails@[...].org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails@[...].org
http://lists.rubyonrails.org/mailman/listinfo/rails
Thread:
Derek Haynes
Elliot Bowes
Derek Haynes
Michael King
|