user3673826 user3673826 - 1 year ago 141
Ruby Question

Ruby on Rails: before_save fields to lowercase

I'm trying to change the fields from the form to lower case before they get saved in the database. This is my code but the output from the database is still in upper case why isnt the code working?

class Transaction < ActiveRecord::Base
validates :name, presence: true
validates :amount, presence: true, numericality: true
before_save :downcase_fields

def downcase_fields

Answer Source

downcase returns a copy of the string, doesn't modify the string itself. Use downcase! instead:

def downcase_fields!

See documentation for more details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download