ArgumentError: wrong number of arguments (1 for 2)
update_column
takes two arguments. You are only passing one.
Instead of:
@post.update_column(:ups => @post[:ups] + 1)
Try:
@post.update_column(:ups, @post[:ups] + 1)
This may seem like two arguments:
:ups => @post[:ups] + 1
but it's actually one hash.
With the more commonly used update_attributes
, you can pass a hash:
@post.update_attributes(:ups => @post[:ups] + 1)
ArgumentError: wrong number of arguments (1 for 2) for update method in rails
Game.find(12).game_categories(55)
returns relation of records, not single record. So in order to update all game_categories of game with id 12 you can use
Game.find(12).game_categories(55).update_all(approved_by: 1)
ArgumentError: wrong number of arguments (given 1, expected 2) for Update_Attribute Method
The first comment on this answer is correct, so I don't know why this person posted as a comment rather than an answer. update_attribute takes two arguments and you are passing it a single hash argument. Your "favorite" method is the equivalent of update_attribute({favorited: true})
when you really want update_attribute(:favorited, true)
Getting at ArgumentError: wrong number of arguments (1 for 2)
Your end
s are mixed up a bit in your last 2 tests. The fully revised file below:
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@user = User.new(name: "Example User", email: "user@example.com")
end
test "should be valid" do
assert @user.valid?
end
test "name should be present" do
@user.name = " "
assert_not @user.valid?
end
test "email should be present" do
@user.email = " "
assert_not @user.valid?
end
test "name should not be too long" do
@user.name = "a" * 51
assert_not @user.valid?
end
test "email validation should reject invalid addresses" do
invalid_addresses = %w[user@example,com user_at_foo.org user.name@example.foo@bar_baz.com foo@bar+baz.com]
invalid_addresses.each do |invalid_address|
@user.email = invalid_address
assert_not @user.valid?
end # end of each block
end # end of test block
test "email addresses should be unique" do
duplicate_user = @user.dup
duplicate_user.email = @user.email.upcase
@user.save
assert_not duplicate_user.valid?
end # end of test block
end # end of class
ROR: wrong number of arguments (given 2, expected 1)
The activeadmin
gem instantiates the ActiveAdmin::OrderClause
class with a couple of arguments (active_admin_config
and order
) as you can see here and here. Fix the initialize
method arguments.
def initialize(active_admin_config, clause)
# ...
end
You should also remove the active_admin_config
argument from the to_sql
method since it is called with no arguments. You can set @active_admin_config
in the initialize
method and add :active_admin_config
to the attr_reader
call to use in the to_sql
method.
module ActiveAdmin
class OrderClause
attr_reader :field, :order, :active_admin_config
def initialize(active_admin_config, clause)
@active_admin_config = active_admin_config
# rest of the code
end
def to_sql
# ...
end
end
end
I would recommend you create a CustomOrderClause
class that inherits from the gem's ActiveAdmin::OrderClause
class and only override the necessary methods. You can then use config.order_clause = CustomOrderClause
when configuring activeadmin in an initializer.
ArgumentError: wrong number of arguments (2 for 1) for 'initialize'?
Your error is in this line:
require 'log4r', :version=>'=1.1.10'
I'm not sure what you tried to do, but require
receives a single argument. The error wrong number of arguments
means that you are trying to call a method with an unexpected number of arguments. (2 for 1)
means you are trying to call a method with one argument with two.
The only method call in initialize
you are calling with two arguments is require
- so this is the method in question.
require
usage is in most cases at the top of ruby files, telling the ruby interpreter which other ruby files should be loaded before loading this file.
require
does not declare gem dependencies, so gem versions are irrelevant here. You can put these in the Gemfile
file.
Related Topics
Writing Ruby Console Output to Text File
How to Figure Out Which Step I'Ve Just Executed in Cucumber's Afterstep Hook
How to Parse Xml Nodes to CSV with Ruby and Nokogiri
Ruby on Rails: Params Is Nil. Undefined Method '[]' for Nil:Nilclass
How to Include Ё in [А-Я] Regexp Char Interval
Building a Simple Search Form in Rails
Can't Setup Ruby Environment - Installing Fii Gem Error
Why Is 032 Different Than 32 in Ruby
Show Markers on Google Maps Dynamically -Rails 3.2
Validate That String Contains Only Allowed Characters in Ruby
Parsing Large Xml with Nokogiri
How to Create an Operator for Deep Copy/Cloning of Objects in Ruby
Does Anyone Have Parsing Rules for the Notepad++ Function List Plugin for Ruby and Rake
How to Simplify or Clean Up This Anagram Method
How to Get a Reference to a Method
Minitest, Test::Unit, and Rails
Undefined Method 'Require_Relative' for Main:Object (Nomethoderror)