在 Rails 3 应用程序中,我正在尝试为使用的模型编写种子(在 db/seeds.rb 中)friendly_id
:
# /db/seeds.rb
Page.create(:title => "Default page", :content => "Default content of the default page")
当我运行rake db:seed
任务失败。以下是运行时的要点--trace
:
rake aborted!
undefined local variable or method `friendly_id' for #<Class:0x007fa1de992ac8>
/Users/cornelius/.rvm/gems/ruby-1.9.2-p290@usg/gems/activerecord-3.2.5/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
/Users/cornelius/Sites/usg/app/models/page.rb:2:in `<class:Page>'
/Users/cornelius/Sites/usg/app/models/page.rb:1:in `<top (required)>'
...
这是模型:
# /app/models/page.rb
class Page < ActiveRecord::Base
extend friendly_id
friendly_id :title, use: :slugged
end
我friendly_id
用作宝石:
# /Gemfile
gem 'friendly_id'
有什么帮助吗?