乘客 – 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


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

查看所有标签

猜你喜欢:

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

你也能看得懂的Python算法书

你也能看得懂的Python算法书

王硕,董文馨,张舒行,张洁 著 / 电子工业出版社 / 2018-11-1 / 59.00

编程的核心是算法,学习算法不仅能教会你解决问题的方法,而且还能为你今后的发展提供一种可能。 《你也能看得懂的Python算法书》面向算法初学者,首先介绍当下流程的编程语言Python,详细讲解Python语言中的变量和循序、分支、循环三大结构,以及列表和函数的使用,为之后学习算法打好基础。然后以通俗易懂的语言讲解双指针、哈希、深度优先、广度优先、回溯、贪心、动态规划和至短路径等经典算法。 ......一起来看看 《你也能看得懂的Python算法书》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

html转js在线工具
html转js在线工具

html转js在线工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具