Jas*_*ett 7 passenger ruby-on-rails-3.2
我正在运行Rails 3.2和最新版本的Authlogic.当我在Mac上本地运行我的应用程序时,它工作正常.当我尝试在我的生产服务器(带有Passenger/Apache的Ubuntu)上运行它时,我得到了这个:
You must establish a database connection before using acts_as_authentic
Run Code Online (Sandbox Code Playgroud)
我不确定如何解决问题.我在今天早些时候发布了这个相关的问题,然后才意识到这个问题比我想象的要广泛.
我解决了这个问题.看看Authlogic的这个片段lib/authlogic/acts_as_authentic/base.rb:
private
def db_setup?
begin
column_names
true
rescue Exception
false
end
end
Run Code Online (Sandbox Code Playgroud)
如果column_names抛出错误,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
Run Code Online (Sandbox Code Playgroud)
如果db_setup?返回false,则Authlogic将抛出异常,但不会抛出相同的异常column_names.
我的问题是column_names抛出这个异常:
/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
Run Code Online (Sandbox Code Playgroud)
这个例外的原因是我的用户表被调用user,而不是users,但Rails没有pluralize_table_names正确地接受我的设置.一旦我解决了我的pluralize_table_names问题(显然这个设置的工作方式已在Rails 3.1中更改),我的Authlogic问题就消失了.
因此,如果您遇到此问题,可能需要尝试以下操作:
'authlogic', :path => '/path/to/authlogic')column_names调用db_setup?beginrescueend我把它固定在我的叉子上.直到Ben有时间合并修复程序,你可以使用Gemfile中的fixed分支解决这个问题.
gem 'authlogic', :git => 'git@github.com:james2m/authlogic.git', :branch => 'fix-migrations'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3248 次 |
| 最近记录: |