friendly_id 4.0.8使用rails 3.0.1 rails生成friendly_id无法正常工作?

时间:2012-09-12 09:26:20

标签: ruby-on-rails-3.1 friendly-id

我正在使用带有rails 3.0.1的friendly_id 4.0.8。我想使用历史记录功能。

当我键入命令rails 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.

是否有一些不同的语法使其有效?

1 个答案:

答案 0 :(得分: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