Overriding an ActiveRecord attribute

Posted by jspooner on Stack Overflow See other posts from Stack Overflow or by jspooner
Published on 2010-05-17T18:33:07Z Indexed on 2010/05/17 19:10 UTC
Read the original article Hit count: 262

Filed under:
|
|

I have a model with a completed:boolean column that I'd like override so I can add some conditional code.

I've never override an ActiveRecord attribute before and wanted to know if the method below is good practice?

class Article < ActiveRecord::Base
  def completed=(b)
    write_attribute(:completed, b)
    # IF b is true then do something
  end
end

© Stack Overflow or respective owner

Related posts about activerecord

Related posts about ruby-on-rails