gpt4 book ai didi

ruby-on-rails - 参数数量错误 [ex :(3 for 2)] in methods [but only pass 2]

转载 作者:行者123 更新时间:2023-12-04 03:54:31 26 4
gpt4 key购买 nike

一个奇怪的问题:

session Controller :

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

用户.rb:

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

我明白了

app/models/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"}

它发生在所有方法上

我的包列表

 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)

使用后出现

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

而且必须要加

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

有人在这样一个基本的奇怪问题上遇到过同样的问题吗?

感谢您的帮助:)

最佳答案

看起来您正在尝试将实例方法作为类方法来调用。因此,您的代码适合在现有用户上调用 @user.authenticate(x,y),但要在您的类上调用 authenticate,您需要将其定义为下面:

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

关于ruby-on-rails - 参数数量错误 [ex :(3 for 2)] in methods [but only pass 2],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5052778/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com