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

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

内容简介:翻译自: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


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

查看所有标签

猜你喜欢:

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

Processing语言权威指南

Processing语言权威指南

Casey Reas、Ben Fry / 张静 / 电子工业出版社 / 2013-10-1 / 139.00

本书介绍了可视化艺术中的计算机编程概念,对开源编程语言Processing作了非常详尽的阐述。学生、艺术家、设计师、建筑师、研究者,以及任何想编程实现绘画、动画和互动的人都可以使用它。书中的大部分章节是短小的单元,介绍Processing的语法和基本概念(变量、函数、面向对象编程),涵盖与软件相关的图像处理、绘制,并且给出了大量简短的原型程序,配以相应的过程图像与注释。书中还有一些访谈文章,与动画......一起来看看 《Processing语言权威指南》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具