奇怪的错误创建了Devise用户

时间:2015-04-24 12:03:01

标签: ruby-on-rails ruby-on-rails-4 devise

我已多次创建设计用户,但这是第一次发生这种情况。 Devise无法创建它创建的文件。我不知道为什么。

rails generate devise user
      invoke  active_record
      create    db/migrate/20150424115858_devise_create_users.rb
      create    app/models/user.rb
      invoke    rspec
      create      spec/models/user_spec.rb
      invoke      fabrication
/Users/moiseszaragoza/.rvm/gems/ruby-2.1.5@app_name/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec': PG::UndefinedTable: ERROR:  relation "users" does not exist (ActiveRecord::StatementInvalid)
LINE 5:                WHERE a.attrelid = '"users"'::regclass
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                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

以下是我的config / application.rb

的副本
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)

module AppName
  class Application < Rails::Application
    config.active_record.raise_in_transactional_callbacks = true
    initializer 'setup_asset_pipeline', :group => :all  do |app|
      app.config.assets.precompile.shift
      app.config.assets.precompile.push(Proc.new do |path|
        File.extname(path).in? [
          '.html', '.erb', '.haml',                 # Templates
          '.png',  '.gif', '.jpg', '.jpeg',         # Images
          '.eot',  '.otf', '.svc', '.woff', '.ttf', # Fonts
        ]
      end)
    end
    I18n.enforce_available_locales = false
    config.before_initialize do
      dev = File.join(Rails.root, 'config', 'config.yml')
      YAML.load(File.open(dev)).each do |key,value|
      ENV[key.to_s] = value
      end if File.exists?(dev)
    end
  end
end

2 个答案:

答案 0 :(得分:3)

您的数据库似乎有问题,您是否配置了database.xml?如果是这样尝试不同版本的设计宝石,请更新它,如果它是最后一个版本,请降级。

答案 1 :(得分:0)

看起来它可能会在调用制作时爆炸,因为我还没有用户表。

我从我的gem文件中删除了gem 'fabrication-rails',然后就可以了

$ rails generate devise user
      invoke  active_record
      create    db/migrate/20150424130126_devise_create_users.rb
      create    app/models/user.rb
      invoke    rspec
      create      spec/models/user_spec.rb
      invoke      factory_girl
      create        spec/factories/users.rb
      insert    app/models/user.rb
       route  devise_for :users