开发者

wrong number of arguments [ex:(3 for 2)] in methods [but only pass 2]

Quite a strange problem :

session_controller:

user = User.authenticate(params[:name], params[:password])

user.rb:

    def authenticate(name, password)
      if user = find_by_name(name)
        if user.hashed_password == encrypt_password(password, user.salt)
        user
        end
      end
    end

I get

app/mod开发者_运维百科els/user.rb:10:in `authenticate'
app/controllers/sessions_controller.rb:27:in `create'

Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"wOQEEKnH68MKewyM2Mpxc9aRoOg8ByXuYJKrMCI17SE=",
 "name"=>"1@1.com",
 "password"=>"[FILTERED]",
 "commit"=>"Connexion"}

it's happend on all methods

my Bundle list

 Gems included by the bundle:
   * abstract (1.0.0)
   * actionmailer (3.1.0.beta)
   * actionpack (3.1.0.beta)
   * activemodel (3.1.0.beta)
   * activerecord (3.1.0.beta)
   * activeresource (3.1.0.beta)
   * activesupport (3.1.0.beta)
   * arel (2.0.8)
   * bcrypt-ruby (2.1.4)
   * builder (3.0.0)
   * bundler (1.1.pre.1)
   * capistrano (2.5.19)
   * erubis (2.6.6)
   * highline (1.6.1)
   * i18n (0.5.0)
   * jquery-rails (0.2.7)
   * mail (2.2.15)
   * mime-types (1.16)
   * net-scp (1.0.4)
   * net-sftp (2.0.5)
   * net-ssh (2.1.0)
   * net-ssh-gateway (1.0.1)
   * newrelic_rpm (2.13.4)
   * polyglot (0.3.1)
   * rack (1.2.1 e3ffeac)
   * rack-cache (1.0)
   * rack-mount (0.6.13)
   * rack-test (0.5.7)
   * rails (3.1.0.beta 289cc15)
   * railties (3.1.0.beta)
   * rake (0.8.7)
   * sqlite3 (1.3.3)
   * sqlite3-ruby (1.3.3)
   * thor (0.14.6)
   * treetop (1.4.9)
   * tzinfo (0.3.24)

It's happend after using

gem 'rails', :git => 'git://github.com/rails/rails.git'

And it was compulsory to add

gem 'rack', :git => 'git://github.com/rack/rack.git'  

Anyone get the same problem on such a basic strange problem?

Thank for your help :)


Looks like you're trying to call a instance method as a class method. So your code would be appropriate for calling @user.authenticate(x,y) on an existing user, but to call authenticate on your class, you need to define it as below:

def self.authenticate(name, password)
  if user = find_by_name(name)
    if user.hashed_password == encrypt_password(password, user.salt)
    user
    end
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜