Pergunta

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.

Foi útil?

Solução

Turns out that the ArgumentError was due to the NewRelic addon. If you're having this issue, go to the command line and type:

heroku addons:remove newrelic:standard --app your_app_name
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top