乘客 – Authlogic无法使用我的Rails 3.2应用程序

栏目: Ruby · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/9518976/authlogic-doesnt-work-with-my-rails-3-2-app
我正在运行Rails 3.2和最新版本的Authlogic.当我在Mac上本地运行我的应用程序时,它工作正常.当我尝试在我的生产服务器(带有Passenger / Apache的Ubuntu)上运行它时,我得到了这个:
You must establish a database connection before using acts_as_authentic

我不确定如何解决问题.我在今天早些时候发布了 this related question ,之前我意识到这个问题比我想象的更广泛.

我解决了这个问题.从Authlogic的lib / authlogic / acts_as_authentic / base.rb看这个片段:

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

如果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

如果是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

这个例外的原因是我的用户表被称为用户,而不是用户,但Rails没有正确地使用我的pluralize_table_names设置.一旦我修复了pluralize_table_names问题(显然这个设置的工作方式已在Rails 3.1中更改),我的Authlogic问题就消失了.

因此,如果您遇到此问题,可能需要尝试以下操作:

>将Authlogic仓库克隆到开发机器上的某个位置

>更改您的Gemfile以使用本地版本的Authlogic(‘authlogic’,:path =>’/ path / to / authlogic’)

>向db_setup添加column_names调用?在开始/救援/结束条款之外

>看看你是否得到了一个不同的,可能更准确和信息量更大的错误,就像我一样

翻译自:https://stackoverflow.com/questions/9518976/authlogic-doesnt-work-with-my-rails-3-2-app


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

四步创业法

四步创业法

[美] Steven Gary Blank / 七印部落 / 华中科技大学出版社 / 2012-8-1 / 48.00

《四步创业法》获李开复推荐,是精益创业理论的奠基之作。作者Steven Gary Blank博士是硅谷资深企业家,他一共创办了八家企业,并担任多家硅谷公司的董事和创业顾问。本书总结作者25年创业经验,提出全新的客户发展方法 (诣在弥补传统产品开发方法的缺陷) ,掀起了硅谷近年精益创业 的浪潮。七印部落正在翻译作者的博客和授课视频,欢迎访问微博:http://weibo.com/7seals ......一起来看看 《四步创业法》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换