Blog Archives

Override/Extend Rails Core classes OR Strip attributes before Save

# active_record_base_extenstion.rb class ActiveRecord::Base before_save :clean_data def clean_data # trim whitespace from beginning and end of string attributes attribute_names.each do |name| if send(name).respond_to?(:strip) send(“#{name}=”, send(name).strip) end end end end

Tagged with: ,
Posted in Uncategorized
StackOverFlow
Categories
Archives