Heroku上的参数错误

时间:2011-09-18 01:16:51

标签: ruby-on-rails-3.1 authlogic usersession

我正在使用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设置,因为它在我需要的示例中显示,但是简单的身份验证。这是我的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

我的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变得明显 - 请参阅解决方案的答案。

1 个答案:

答案 0 :(得分:0)

原来,ArgumentError是由NewRelic插件引起的。如果遇到此问题,请转到命令行并键入:

heroku addons:remove newrelic:standard --app your_app_name