Mass Assginment and has_many others.build


#1

Typically, when one creates a has_many associated table one does this:

hasone.hasmany.build({attribute hash},{attribute hash},…} or
hasone.hasmany.create({attribute hash}, …

However, if mass assignment is turned off (attr_accessible => nil), then
I cannot seem to set the attributes directly.

For example, in a console session I do this:

me = Entity.new
=> …

me.attribute = …

me.save!
=> true

mi = me.identifiers.build
=> …

mi.entity_id
=> 1

mi.identifier_type = ‘post’
=> ‘post’

mi.identifier_type
=> nil

What is going on and how do I directly set association attributes?


#2

Rails 2.3.2

This seems related specifically to the suffices _type and _value.
Attributes ending in either of these strings are not processed by the
attribute= method. if #write_attribute(“something_type”, “a value”) is
called instead, then the somthing-type= method is again bypassed and the
attribute is set to the literal value provided instead.

I have raised a ticket for this:

http://rails.lighthouseapp.com/projects/8994/tickets/2314-v-232-appropriates-attributed-ending-in-_type-and-_value