Reputation: 1646
How does this syntax work?
before_validation { |user| user.email = email.downcase }
I would think that it would need to be this:
before_validation { |user| user.email = user.email.downcase }
Thanks for your help!
Upvotes: 4
Views: 153
Reputation: 1570
It works, but keep the DRY principle of Ruby. This would be better:
before_validation { |user| user.email.downcase! }
!
reflects the changes back onto the receiving object and it also saves a few keystrokes.
Upvotes: -1
Reputation: 47472
It work because
before_validation { |user| user.email = email.downcase }
SAME AS
before_validation { |user| user.email = self.email.downcase }
Upvotes: 5