Rake - 未初始化的常量LoadPermissionRanks :: Fixtures

时间:2013-08-29 06:11:57

标签: ruby-on-rails ruby activerecord migration

我正在尝试初始化一个不会改变的表记录。

我将记录放在此permissionrank.yml文件中:

player:
  id: 1
  label: Player
  badge: NIL

bronze helper:
  id: 2
  label: Bronze Helper
  badge: STF_HELP_BRZ

silver helper:
  id: 3
  label: Silver Helper
  badge: STF_HELP_SLV

gold helper:
  id: 4
  label: Gold Helper
  badge: STF_HELP_GLD

moderator:
  id: 5
  label: Moderator
  badge: STF_MOD

senior moderator:
  id: 6
  label: Moderator
  badge: STF_MOD

administrator:
  id: 7
  label: Administrator
  badge: STF_ADM

senior administrator:
  id: 8
  label: Administrator
  badge: STF_ADM

这是我的迁移:

require 'active_record/fixtures'

class LoadPermissionRanks < ActiveRecord::Migration
  def self.up
    down
    directory = File.join(File.dirname(__FILE__), "init_data")
    Fixtures.create_fixtures(directory, "permissionrank")
  end

  def self.down
    PermissionRank.delete_all
  end
end

当我运行迁移时,我得到了这个:

uninitialized constant LoadPermissionRanks::Fixtures/home/guilmon/Documents/A2 Computing Project/Software Development/Client/db/migrate/20130829051940_load_permission_ranks.rb:7:in `up'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:534:in `up'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:574:in `exec_migration'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:555:in `block (2 levels) in migrate'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:554:in `block in migrate'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:553:in `migrate'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:709:in `migrate'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:959:in `block in execute_migration_in_transaction'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:1005:in `block in ddl_transaction'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/transactions.rb:209:in `transaction'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:1005:in `ddl_transaction'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:920:in `block in migrate'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `each'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `migrate'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/home/guilmon/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate

有没有其他方法可以做到这一点?难道我做错了什么? 我正在使用Rails 4和Ruby 2.0.0

0 个答案:

没有答案