Currently I'm doing the following in the model:
before_save :to_lower
before_create :to_lower
def to_lower
self.name = self.name.downcase
end
Seems pretty repetitive to me.
You don't need the before_create if you already have before_save.
before_save { |user| user.name = user.name.downcase }
I generally handle such cases by:
def name= name
super(name.try(:downcase))
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With