Wrong number of arguments (2 for 1) attributes_with_quotes

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:inupdate_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:inupdate_without_timestamps’
vendor/rails/activerecord/lib/active_record/timestamp.rb:38:in update' vendor/rails/activerecord/lib/active_record/base.rb:1991:increate_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:insave_without_validation’
vendor/rails/activerecord/lib/active_record/validations.rb:891:in
save_without_transactions' vendor/rails/activerecord/lib/active_record/transactions.rb:105:insave’
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in
transaction' vendor/rails/activerecord/lib/active_record/transactions.rb:77:intransaction’
vendor/rails/activerecord/lib/active_record/transactions.rb:97:in
transaction' vendor/rails/activerecord/lib/active_record/transactions.rb:105:insave’
vendor/rails/activerecord/lib/active_record/transactions.rb:117:in
rollback_active_record_state!' vendor/rails/activerecord/lib/active_record/transactions.rb:105:insave’
vendor/rails/activerecord/lib/active_record/base.rb:1790:in
update_attributes' app/controllers/users_controller.rb:57:inupdate_password’
app/controllers/users_controller.rb:56:in update_password' /usr/local/bin/mongrel_rails:18:inload’
/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.

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. [email protected]

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs