Ruby on Rails Wednesday, April 29, 2015

Hi Chris.
It's just a simple validation method:

validate :custom

def custom
    if self.text.blank? and self.persisted?
      return errors.add(:base, 'Error')
    else
end

Every custom method has this problem.

On Wednesday, April 29, 2015 at 12:52:55 PM UTC-3, Chris Lerum wrote:
It may help if you showed us this code of which you speak.

On Wednesday, April 29, 2015 at 10:52:06 AM UTC-4, Gm wrote:
Hi, I'm using a custom validation method to validate some logic.
But I realized that the database query is running two times.
So the database is being called twice.

The validation method just display an error if array items are duplicated.

Log:

Questao Load (0.4ms)
["a", "a"]

Questao Load (0.4ms)
["a", "ab"]

What's wrong with my code ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/94347f93-a665-4bae-80f1-aaece70259e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment