Home > Doing things in models on save/update

Doing things in models on save/update

June 19th, 2006

So, I wanted to do some sweet gsubbing before the save of projects in Rails. I found the API docs had a wealth of information about this, but I figured I’d post my method anyway:


  before_create :fix_amount
  before_update :fix_amount

Now you just define them under private in the model:


  def fix_amount
    self.amount.gsub!(/^\$/, "")
  end

This takes those pesky $’s right out, back to the back yard where they belong.


, ,

  1. June 19th, 2006 at 13:31 | #1

    We noticed that your blog have some Ruby On Rails releated content, and that is why we would like to invite you to register yourself and your blog at RubyCorner, a directory of Ruby related blogs: http://www.rubycorner.com/
    We like to think about RubyCorner as a "meeting place" for the community, also as a "focal point" where the people new to this technology can quickly tune into the pulse of the community. Registering your blog will help build a valuable resource for this growing community.

    Regards

  1. No trackbacks yet.
Comments are closed.