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.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-03-20 21: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.
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-03-21 14:29
(Received via mailing list)
On Fri, Mar 20, 2009 at 3:32 PM, James Byrne <lists@ruby-forum.com>
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.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-03-21 15:56
David Chelimsky 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...
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-03-21 15:57
James Byrne 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.