Can anyone help me?? I validate a form-field: protected def validate errors.add(:name, "should be longer than 2 chars") unless name.length <= 2 end I want to check the variable name. It should have a size over 2 characters. But my function "validate" doesn''t run! Why ??? -- Posted via http://www.ruby-forum.com/.
On 8/8/06, Marco R. <ribi@schwingerverband.ch> wrote:> > Can anyone help me?? > > I validate a form-field: > > > protected > def validate > errors.add(:name, "should be longer than 2 chars") unless name.length > <= 2 > end > > > I want to check the variable name. It should have a size over 2 > characters. But my function "validate" doesn''t run! Why ??? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Could it be a typo? <= 2 instead of > 2 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060808/e9845b4d/attachment.html
> > errors.add(:name, "should be longer than 2 chars") unless name.length > > <= 2> > I want to check the variable name. It should have a size over 2 > > characters. But my function "validate" doesn''t run! Why ???well I also vote for the typo... or anyway you have to put > 2 if you want the error to be added using "unless" Btw my suggestiong is to use the validates heaven: validates_length_of :fav_bra_size, :minimum=>1, :too_short=>"please enter at least %d character" HTH Enrico -- "The only thing necessary for the triumph of evil is for good men to do nothing" Edmund Burke