Gm11
(Gm)
April 29, 2015, 2:52pm
1
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.
It may help if you showed us this code of which you speak.
Gm11
(Gm)
April 29, 2015, 3:58pm
3
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.
Colin_Law
(Colin Law)
April 29, 2015, 4:14pm
4
You are missing an end statement so whatever follows after this will
be executed as part of the validation. Presumably you have an extra
end later on which allows it to run.
Colin
Gm11
(Gm)
April 29, 2015, 4:14pm
5
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
Colin_Law
(Colin Law)
April 29, 2015, 4:18pm
6
What code are you running that invokes the validation?
Colin