0
votes

Ruby Version: 1.8
Rails Version: 2.3

I have a class in which I have written 'attr_writer :content' and I have a custom reader method 'content'. Doing it this way, content is NULL. I've checked out the values and they look like this:

--- &id001 !ruby/object:Email 
attributes: 
  created_at: 
  expired_at: 
  updated_at: 
  subject: Test Eblast
  content: 
  inline_attachments: 
  attachments: 
attributes_cache: 
  expired_at: 
changed_attributes: 
  subject: 
content: This is the body
errors: !ruby/object:ActiveRecord::Errors 
  base: *id001
  errors: !omap []

new_record: true

Notice the indentation of "content:" on the 2nd instance. It isn't being written as an attribute, but something else...while the actual attribute isn't being updated. When I take out 'attr_writer' and write my own getter/setter methods explicitly, everything works. Why is that?

1

1 Answers

3
votes

attr_writer creates getter and setter methods for an instance variable, not an ActiveRecord attribute.