Ruby on Rails Wednesday, April 29, 2015

If I put a simple p "a" inside the method, two inspects are displayed:

  (0.1ms)  BEGIN
"a"
   (0.1ms)  ROLLBACK
   (0.1ms)  BEGIN
"a"
   (0.1ms)  ROLLBACK

On Wednesday, April 29, 2015 at 12:58:39 PM UTC-3, Gm wrote:
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/e58fc57f-d736-4172-a8a3-1107c7a04438%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment