友情ID不适用于Rails 4.2?

时间:2015-01-05 21:59:58

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

我最近升级到rails 4.2,我发现友好ID已停止工作。不确定这是一个错误,还是我真的只是在使用友好ID。

更新后我的测试开始失败,例如我有以下测试:

  context "Fiendly ID" do
    it "should find by name" do
      permission = FactoryGirl.create(:can_read)
      Xaaron::Permission.find(permission.permission_name.parameterize).should_not eql nil
    end
  end

这个测试永远不会失败,但现在它会吐出来:

 Failure/Error: Xaaron::Permission.find(permission.permission_name.parameterize).should_not eql nil
 ActiveRecord::RecordNotFound:
   Couldn't find Xaaron::Permission with 'id'=can_read2
 # ./.bundle/gems/gems/activerecord-4.2.0/lib/active_record/core.rb:154:in `find'
 # ./spec/models/xaaron/permission_spec.rb:21:in `block (3 levels) in <top (required)>'

考虑到这一点,这是我的模型:

module Xaaron
  class Permission < ActiveRecord::Base
    extend FriendlyId
    friendly_id :permission_name, use: [:slugged, :finders, :history]

    has_many :roles_permissions
    has_many :roles, :through => :roles_permissions

    validates :permission_name, presence: true, uniqueness: true

    def should_generate_new_friendly_id?
      permission_name_changed?
    end
  end
end

注意:finders。我正在运行5.0.3 for Friendly ID。这是活动记录中的新内容还是我使用友好ID失败了?

1 个答案:

答案 0 :(得分:3)

finders模块与Rails 4.2兼容。仅在5.1中。版本(尚未发布)。您当然可以测试该版本,但请记住它仍处于测试阶段。

gem "friendly_id", "5.1.0.beta.1"