2012-03-01 4 views
7

저는 Rails 3.2와 Authlogic의 최신 버전을 실행하고 있습니다. 내 Mac에서 로컬로 응용 프로그램을 실행할 때 제대로 작동합니다. 내 프로덕션 서버 (여객/아파치와 우분투)에서 실행하려고 할 때,이 얻을 :Authlogic이 내 Rails 3.2 앱에서 작동하지 않습니다.

You must establish a database connection before using acts_as_authentic 

내가 문제를 해결하는 방법을 모르겠어요. 나는 그 문제가 내가 생각했던 것보다 더 광범위하다는 것을 깨닫기 전에 오늘 this related question을 게시했다.

+0

이전에는 큰 authlogic 팬이었고 LDPA, RPX 등의 어댑터를 포함하여 2.x 시대에 많은 앱을 사용했습니다. 이후 대부분을 3.0.x 및 3.2로 업그레이드했지만 그 과정에서 전반적으로 더 쉽게 마이그레이션 할 수 있다고 결정했습니다. 쉽고 코드가 더 깨끗합니다 (일반적으로 3.0 시대에 설계 되었기 때문에). 이것은 귀하의 질문에 대답하지 않습니다 .. 난 그냥 그것을 언급 authlogic 다시 물고 유지하는 경우 명심하십시오; 장치로 전환하는 것은 그리 큰 문제가 아니며, 기본으로 자리 잡기 위해 오래 걸리지 않을 것입니다. – tardate

+0

나는 결국 다른 날 Devise로 전환했다. 그것은 놀라 울 정도로 쉽고 고통없는 스위치였습니다. –

+0

이것은 수정 된 것 같습니다. 우선 master 브랜치에서 pull하기 위해'gem 'authlogic, : git =>'git : // github.com/binarylogic/authlogic.git''을 gemfile에 사용해야합니다. –

답변

9

문제를 발견했습니다. Authlogic의 lib/authlogic/acts_as_authentic/base.rb에서이 조각 봐 : column_names 오류가 발생

private 
     def db_setup? 
     begin 
      column_names 
      true 
     rescue Exception 
      false 
     end 
     end 

경우, db_setup?는 false를 돌려줍니다. base.rb에서도이 다른 기능을 봐 :

def acts_as_authentic(unsupported_options = nil, &block) 
     # Stop all configuration if the DB is not set up 
     raise StandardError.new("You must establish a database connection before using acts_as_authentic") if !db_setup? 

     raise ArgumentError.new("You are using the old v1.X.X configuration method for Authlogic. Instead of " + 
     "passing a hash of configuration options to acts_as_authentic, pass a block: acts_as_authentic { |c| c.my_option = my_value }") if !unsupported_options.nil? 

     yield self if block_given? 
     acts_as_authentic_modules.each { |mod| include mod } 
    end 

db_setup? false를 반환하는 경우, Authlogic가 column_names에 의해 throw 예외, 하지만 같은 예외가 발생합니다.

내 문제는 column_names이 예외 던지고이었다 내 사용자 테이블이 없습니다 users, user라고되어

/Users/jason/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `async_exec': PG::Error: ERROR: relation "users" does not exist (ActiveRecord::StatementInvalid) 
LINE 4:    WHERE a.attrelid = '"users"'::regclass 
             ^
:    SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull 
       FROM pg_attribute a LEFT JOIN pg_attrdef d 
       ON a.attrelid = d.adrelid AND a.attnum = d.adnum 
      WHERE a.attrelid = '"users"'::regclass 
       AND a.attnum > 0 AND NOT a.attisdropped 
      ORDER BY a.attnum 

그리고 그 예외에 대한 이유를하지만, 레일이 제대로 설정 내 pluralize_table_names에 따기되지 않았습니다 . pluralize_table_names 문제 (이 설정이 작동하는 방식이 Rails 3.1에서 변경된 것 같습니다)를 수정하면 Authlogic 문제가 사라졌습니다. 그래서

이 문제가 발생하는 경우, 당신이 시도 할 수 있습니다 : (Authlogic의 로컬 버전을 사용하도록 Gemfile을 변경 dev에 기계

  • 어딘가에에 Authlogic의 REPO를

    • 복제를 'authlogic', :path => '/path/to/authlogic')
    • 은 다른 잠재적 m를 얻는 경우에 참조 begin/rescue/end
    • 외부 db_setup?column_names 호출을 추가 광산 정확하고 유익한, 오류, 내가 한 것처럼
  • +0

    물론 Authlogic이이 문제의 가능성을 알고 있다면 정말 좋을 것입니다. Authlogic에 패치를 적용 할 수 있도록이 특정 문제를 감지하는 방법을 묻는 새로운 질문을 올렸습니다 ... 좋은 생각이라고 가정합니다. http://stackoverflow.com/questions/9557860/how-do-i-catch-this-specific-error-in-rails#comment12115170_9557860 –

    5

    나는 내 포크에 이것을 해결했습니다. Ben이 수정 사항을 병합 할 때까지 Gemfile의 고정 분기를 사용하여이 문제를 해결할 수 있습니다.

    gem 'authlogic', :git => '[email protected]:james2m/authlogic.git', :branch => 'fix-migrations' 
    
    4

    답변을 요청한이 페이지에 온 다른 사람들에게.

    하나의 이유는 테스트 데이터베이스를 만들지 않았기 때문일 수 있습니다.

    $ RAILS_ENV = 테스트 레이크 DB를 :

    그냥 실행 DB를 만들 :

    관련 문제