Heroku 上的参数错误
我正在使用 Rails 3.1 和 Authlogic 3.0.3。我的应用程序部署在 Heroku 上。在本地,一切都工作得很好,但是,当我部署到 Heroku 时,出现以下错误:
ArgumentError (wrong number of arguments (3 for 2)):
app/controllers/application_controller.rb:38:in `current_user_session'
app/controllers/application_controller.rb:43:in `current_user'
app/controllers/application_controller.rb:5:in `block in <class:ApplicationController>'
使用更完整的堆栈跟踪:
vendor/plugins/rpm/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb:16:in `log_with_newrelic_instrumentation'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:550:in `exec_query'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:679:in `table_exists?'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/primary_key.rb:41:in `get_primary_key'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/primary_key.rb:25:in `reset_primary_key'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/primary_key.rb:16:in `primary_key'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/session.rb:48:in `session_credentials'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/session.rb:33:in `persist_by_session'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:413:in `_run_persist_callbacks'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/callbacks.rb:90:in `persist'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/persistence.rb:55:in `persisting?'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/persistence.rb:39:in `find'
app/controllers/application_controller.rb:38:in `current_user_session'
app/controllers/application_controller.rb:43:in `current_user'
app/controllers/application_controller.rb:5:in `block in <class:ApplicationController>'
我有 Authlogic 设置,如示例中所示,因为我需要简单的身份验证。 中的代码
class ApplicationController < ActionController::Base
protect_from_forgery
layout 'application'
before_filter { |c| Authorization.current_user = current_user } #this is line 5
helper_method :current_user, :current_user_session
# erroneous stuff removed
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find #line 43
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user #line 38
end
end
这是我的 ApplicationController:和我的 UserSession:
class UserSession < Authlogic::Session::Base
find_by_login_method :find_by_anything
end
,它调用 User: 中的方法:
class User < ActiveRecord::Base
attr_accessible :email, :password, :remember_me
acts_as_authentic do |c|
c.login_field = 'name'
c.require_password_confirmation = false
c.validates_format_of_login_field_options = {:with => /^[a-zA-Z0-9]+$/, :message => "should use only letters and numbers, no other characters."}
c.validates_length_of_login_field_options = {:within => 5..25}
end
def self.find_by_anything(login)
# Postgres and SQLite use a case sensitive search, so we need to make it case insensitive
find_by_smart_case_login_field(login) || find_by_email(login)
end
我的猜测是 UserSession.find 是罪魁祸首,但我一生都无法解决该问题。我已经尝试了两天的所有方法,但日志不是很有帮助,而且我似乎无法浏览源代码。环境之间的唯一区别是我在本地使用 MySQL,而 heroku 使用 Postgres。
编辑:问题不是 Authlogic,而是 NewRelic。只是碰巧错误会冒出来,并通过 Authlogic 变得明显——请参阅答案以获取解决方案。
I'm using Rails 3.1 with Authlogic 3.0.3. I have my application deployed on Heroku. Locally, everything works perfectly fine, however, when I deploy to Heroku I get the following error:
ArgumentError (wrong number of arguments (3 for 2)):
app/controllers/application_controller.rb:38:in `current_user_session'
app/controllers/application_controller.rb:43:in `current_user'
app/controllers/application_controller.rb:5:in `block in <class:ApplicationController>'
With the fuller stacktrace:
vendor/plugins/rpm/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb:16:in `log_with_newrelic_instrumentation'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:550:in `exec_query'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:679:in `table_exists?'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/primary_key.rb:41:in `get_primary_key'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/primary_key.rb:25:in `reset_primary_key'
.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/primary_key.rb:16:in `primary_key'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/session.rb:48:in `session_credentials'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/session.rb:33:in `persist_by_session'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:413:in `_run_persist_callbacks'
.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/callbacks.rb:90:in `persist'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/persistence.rb:55:in `persisting?'
.bundle/gems/ruby/1.9.1/gems/authlogic-3.0.3/lib/authlogic/session/persistence.rb:39:in `find'
app/controllers/application_controller.rb:38:in `current_user_session'
app/controllers/application_controller.rb:43:in `current_user'
app/controllers/application_controller.rb:5:in `block in <class:ApplicationController>'
I have Authlogic setup as it's shown in the examples as I need but simple authentication. This is the code in my ApplicationController:
class ApplicationController < ActionController::Base
protect_from_forgery
layout 'application'
before_filter { |c| Authorization.current_user = current_user } #this is line 5
helper_method :current_user, :current_user_session
# erroneous stuff removed
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find #line 43
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user #line 38
end
end
And my UserSession:
class UserSession < Authlogic::Session::Base
find_by_login_method :find_by_anything
end
Which calls the method in User:
class User < ActiveRecord::Base
attr_accessible :email, :password, :remember_me
acts_as_authentic do |c|
c.login_field = 'name'
c.require_password_confirmation = false
c.validates_format_of_login_field_options = {:with => /^[a-zA-Z0-9]+$/, :message => "should use only letters and numbers, no other characters."}
c.validates_length_of_login_field_options = {:within => 5..25}
end
def self.find_by_anything(login)
# Postgres and SQLite use a case sensitive search, so we need to make it case insensitive
find_by_smart_case_login_field(login) || find_by_email(login)
end
My guess is that the UserSession.find is the culprit, but I cannot for the life of me resolve the issue. I've tried everything for two days but the logs aren't very helpful and I can't seem to navigate my way through the source code. The only difference between the environments is locally I'm using MySQL and heroku uses Postgres.
EDIT: the issue was not Authlogic, it was NewRelic. It just happened that the error would bubble up and become apparent through Authlogic -- see answer for solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,ArgumentError 是由 NewRelic 插件造成的。如果您遇到此问题,请转到命令行并输入:
Turns out that the ArgumentError was due to the NewRelic addon. If you're having this issue, go to the command line and type: