Ruby on Rails - Can I modify data before it is saved?
ruby, ruby-on-rails
Solution
you should overwrite the attribute writer:
class User < ActiveRecord::Base
def username=(val)
write_attribute(:username, val.downcase)
end
end
Problem
Quick example: A user enters a username into a form, and I need to make that text username before storing it in the app's database, thereby making it permanently lowercase. Where would I put this code, and how would I access the data to be lowercased? Thanks.