0

我将friendly_id 4.0.8 与rails 3.0.1 一起使用。我想使用历史记录功能。

当我键入 commandrails generate friendly_id时,它会失败并显示以下错误消息:

[WARNING] Could not load generator "generators/friendly_id_generator". Error: ActiveRecord is not missing constant Migration!.
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:479:in `load_missing_constant'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:183:in `rake_original_const_missing'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in `each'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:181:in `rake_original_const_missing'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
/usr/lib/ruby/gems/1.8/gems/friendly_id-4.0.8/lib/generators/friendly_id_generator.rb:8
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `load_dependency'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `load_dependency'
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.

是否有一些不同的语法可以使它工作?

4

1 回答 1

1

我现在通过手动生成迁移脚本使其正常工作

rails generate migration create_friendly_id_slugs

然后将迁移脚本的内容替换为 gems/friendly_id-4.0.8/lib/friendly_id/migration.rb 中的内容,如下所示:

class CreateFriendlyIdSlugs < ActiveRecord::Migration
  def self.up
    create_table :friendly_id_slugs do |t|
      t.string   :slug,           :null => false
      t.integer  :sluggable_id,   :null => false
      t.string   :sluggable_type, :limit => 40
      t.datetime :created_at
    end
    add_index :friendly_id_slugs, :sluggable_id
    add_index :friendly_id_slugs, [:slug, :sluggable_type], :unique => true
    add_index :friendly_id_slugs, :sluggable_type
  end

  def self.down
    drop_table :friendly_id_slugs
  end
end

然后运行rake db:migrate

于 2012-09-12T09:32:38.633 回答