Why is my default attribute accessor not being overwritten?

I have an Article model. The database schema has several columns including 'title'. I am trying to provide my own getter in place of the method_missing-provided getter. At present I am trying simply:

class Article < ActiveRecord::Base
  def title
    "blah"
  end
end

but when I reload the view the title field continues to be sourced from the database. (My server environment is development and I'm riding Rails 3.1.0.) Any ideas?

Upvotes: 1

Views: 315

Answers (1)

iain
iain

Reputation: 16274

Input helpers don't use the normal accessor if there is a 'before_type_cast' variant, so in your case, it is accessing title_before_type_cast.

Either also define that, or choose another method name altogether. I would advise the latter, because overriding accessors is confusing, even without this complication. Don't fight ActiveRecord, you won't win.

Upvotes: 2

Related Questions