Forum: RSpec OT: SIT - how to turn it off

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James B. (Guest)
on 2009-03-20 22:32
Pardon the intrusion but if somebody knows how to turn off Rails special
treatment of attributes ending in _type and _value I would dearly like
to have this information.

Workarounds are accepted too.

I am trying to initialise an associated row that contains the columns
identifier_type and identifier_value.  The statement

  model.association.create!(:column_type => 'X', :column_value => 'Y')

leaves association.column_type and association.column_value attributes
with VALUES  NULL in the resulting generated SQL code.  I really need
Rails to accept the values that I provide.
David C. (Guest)
on 2009-03-21 15:29
(Received via mailing list)
On Fri, Mar 20, 2009 at 3:32 PM, James B. <removed_email_address@domain.invalid>
wrote:
> Pardon the intrusion but if somebody knows how to turn off Rails special
> treatment of attributes ending in _type and _value I would dearly like
> to have this information.
>
> Workarounds are accepted too.
>
> I am trying to initialise an associated row that contains the columns
> identifier_type and identifier_value.  The statement
>
>  model.association.create!(:column_type => 'X', :column_value => 'Y')

What type of association? There are many and they are all handled
quite differently.

>
> leaves association.column_type and association.column_value attributes
> with VALUES  NULL in the resulting generated SQL code.  I really need
> Rails to accept the values that I provide.
James B. (Guest)
on 2009-03-21 16:56
David C. wrote:

>
> What type of association? There are many and they are all handled
> quite differently.
>

In this particular case this was a has_many / belongs_to pair and I was
attempting a parent.child.create({}) call.  I discovered thereby that
Rails, at least in version 2.3.2, evidently does not permit mass
assignment of attributes ending in _type or _value; apparently
regardless of their presence in an attr_accessible call.

However, this problem proved serendipitous.  In consequence I have
discovered a great deal regarding problems with mass assignment. The
result is that I have instead turned off mass assignment for the entire
application.  This, needless to say, has broken a great deal of my tests
and functioning code but I am mostly finished resolving those problems.

I found a good discussion of this problem and some solutions at:

  http://railspikes.com/2008/9/22/is-your-rails-appl...
James B. (Guest)
on 2009-03-21 16:57
James B. wrote:
> In this particular case this was a has_many / belongs_to pair and I was
> attempting a parent.child.create({}) call.

S/B: parent.children.create({})
This topic is locked and can not be replied to.