# Wrong number of arguments (2 for 1) attributes\_with\_quotes

**URL:** <https://www.ruby-forum.com/t/wrong-number-of-arguments-2-for-1-attributes-with-quotes/118117>\
**Category:** Rails\
**Created:** [October 24, 2007, 12:16am UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-2-for-1-attributes-with-quotes/118117 "2007-10-24T00:16:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8c91f0/32.png) [@chas](https://www.ruby-forum.com/u/chas)\
**Post date:** [October 24, 2007, 12:16am UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-2-for-1-attributes-with-quotes/118117/1 "2007-10-24T00:16:37Z")

</div>

I get this error whenever I use update\_attributes. I am using rails  
v.8008. I’ve uninstalled the rails gem, so I am definitely using the  
rails in vendor/rails (v. 8008).

There was a change made to attributes\_with\_quotes to add a second  
argument:

# Returns copy of the attributes hash where all the values have been

# safely quoted for use in an SQL statement.

def attributes\_with\_quotes(  
include\_primary\_key = true, include\_readonly\_attributes = true )  
quoted = attributes.inject({}) do |quoted, (name, value)|  
if column = column\_for\_attribute(name)  
quoted[name] = quote\_value(value, column) unless  
!include\_primary\_key &&  
column.primary  
end  
quoted  
end  
include\_readonly\_attributes ? quoted :  
remove\_readonly\_attributes(quoted)  
end

The call in base.rb:1998 looks like this:

# Updates the associated record with values matching those

# of the instance attributes. Returns the number of affected rows.

def update  
quoted\_attributes = attributes\_with\_quotes(false, false)

Here is the stack trace:

vendor/rails/activerecord/lib/active\_record/base.rb:1998:in  
`attributes_with_quotes' vendor/rails/activerecord/lib/active_record/base.rb:1998:in`update\_without\_lock’  
vendor/rails/activerecord/lib/active\_record/locking/optimistic.rb:70:in  
`update_without_callbacks' vendor/rails/activerecord/lib/active_record/callbacks.rb:240:in`update\_without\_timestamps’  
vendor/rails/activerecord/lib/active\_record/timestamp.rb:38:in `update' vendor/rails/activerecord/lib/active_record/base.rb:1991:in`create\_or\_update\_without\_callbacks’  
vendor/rails/activerecord/lib/active\_record/callbacks.rb:213:in  
`create_or_update' vendor/rails/activerecord/lib/active_record/base.rb:1743:in`save\_without\_validation’  
vendor/rails/activerecord/lib/active\_record/validations.rb:891:in  
`save_without_transactions' vendor/rails/activerecord/lib/active_record/transactions.rb:105:in`save’  
vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract/database\_statements.rb:66:in  
`transaction' vendor/rails/activerecord/lib/active_record/transactions.rb:77:in`transaction’  
vendor/rails/activerecord/lib/active\_record/transactions.rb:97:in  
`transaction' vendor/rails/activerecord/lib/active_record/transactions.rb:105:in`save’  
vendor/rails/activerecord/lib/active\_record/transactions.rb:117:in  
`rollback_active_record_state!' vendor/rails/activerecord/lib/active_record/transactions.rb:105:in`save’  
vendor/rails/activerecord/lib/active\_record/base.rb:1790:in  
`update_attributes' app/controllers/users_controller.rb:57:in`update\_password’  
app/controllers/users\_controller.rb:56:in `update_password' /usr/local/bin/mongrel_rails:18:in`load’  
/usr/local/bin/mongrel\_rails:18

It looks to me like attributes\_with\_quotes takes two arguments, so I do  
not understand “(2 for 1).”

This was working fine before upgrading to the latest Edge Rails.

Any ideas as to what the problem might be?

Thanks,

Chas.

---

<div class="post-metadata">

**Author:** ![chas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8c91f0/32.png) [@chas](https://www.ruby-forum.com/u/chas)\
**Post date:** [October 24, 2007, 1:55am UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-2-for-1-attributes-with-quotes/118117/2 "2007-10-24T01:55:22Z")

</div>

Definitely very weird… not seeing anything in base or optimistic  
that could cause this to screw up. I would say that maybe there’s a  
plugin overriding that method somewhere, but you would think that  
would show up in the stack trace then.

Well, first, for a sanity check, create a new project and just make a  
simple table and model. See if you get the error there. I doubt you  
will or someone else would have complained about this (not finding  
anything in the rails trac). Also, try grepping through the entire  
project for anything that might redefine attributes\_with\_quotes.

Ultimately, if you can’t sort it out, I would open a bug and roll back  
to a previous revision.

b

On Oct 23, 12:16 pm, Charles M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![chas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8c91f0/32.png) [@chas](https://www.ruby-forum.com/u/chas)\
**Post date:** [October 24, 2007, 10:41am UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-2-for-1-attributes-with-quotes/118117/3 "2007-10-24T10:41:24Z")

</div>

The problem was with the Better Nested Set plugin.

This:

def attributes\_with\_quotes(include\_primary\_key = true) #:nodoc:  
attributes.inject({}) do |quoted, (name, value)|  
if column = column\_for\_attribute(name)  
quoted[name] = quote\_value(value, column) unless  
!include\_primary\_key &&  
(column.primary ||  
[acts\_as\_nested\_set\_options[:left\_column],  
acts\_as\_nested\_set\_options[:right\_column]].include?(column.name))  
end  
quoted  
end  
end

Should be this:

def attributes\_with\_quotes(include\_primary\_key = true,  
include\_readonly\_attributes = true) #:nodoc:  
quoted = attributes.inject({}) do |quoted, (name, value)|  
if column = column\_for\_attribute(name)  
quoted[name] = quote\_value(value, column) unless  
!include\_primary\_key &&  
(column.primary ||  
[acts\_as\_nested\_set\_options[:left\_column],  
acts\_as\_nested\_set\_options[:right\_column]].include?(column.name))  
end  
quoted  
end  
include\_readonly\_attributes ? quoted :  
remove\_readonly\_attributes(quoted)  
end

---

<div class="post-metadata">

**Author:** ![chas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8c91f0/32.png) [@chas](https://www.ruby-forum.com/u/chas)\
**Post date:** [December 23, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-2-for-1-attributes-with-quotes/118117/4 "2007-12-23T18:45:01Z")

</div>

Hey Charles,

I also found that when I had an old rails installation this error would  
not show up. I dont know why ( maybe because acts\_asnested\_set was also  
installed ? ). Now that I switched to rails 2 (2.0.2) I got this error  
too, but I fixed with your code.

Thanks
