Forum: Ruby on Rails Mass Assginment and has_many

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
James B. (Guest)
on 2009-03-23 18:57
Typically, when one creates a has_many associated table one does this:{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 =
=> ...
>> me.attribute = ...
=> true
>> mi =
=> ...
>> 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?
James B. (Guest)
on 2009-03-23 19:49
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:
This topic is locked and can not be replied to.