Rails:ActiveAdmin不能与Friendly_id一起工作
问题描述:
我设置了ActiveAdmin来管理网站上的用户,Friendly_id用于可读的网址。当我去/管理/用户,它抛出这个错误:Rails:ActiveAdmin不能与Friendly_id一起工作
Undefined method `per' for #<User::FriendlyIdActiveRecordRelation:0x007fdb61a38d30>
friendly_id如何建立用户模型:
class User < ActiveRecord::Base
#...
extend FriendlyId
friendly_id :name, use: :slugged
end
我能找到的这两个之间的冲突的唯一资源宝石是这个问题ActiveRecord::ReadOnlyRecord when using ActiveAdmin and Friendly_id这似乎是一个不同的问题,解决方案不适用于我的情况。有关如何解决这个问题的任何建议?
答
我发现它实际上不是friendly_id
的问题,而是will_paginate
,如https://github.com/gregbell/active_admin/issues/670所述。切换到kaminari
分页解决了我的问题。
答
我也遇到过这个问题,发现friendly_id
覆盖to_param
方法,所以只是重新覆盖它。这个对我有用。
ActiveAdmin.register User do
before_filter do
User.class_eval do
def to_param
id.to_s
end
end
end
end
答
我能解决它this way:
Unless you use the :finders addon, you should modify your admin controllers for models that use FriendlyId with something similar to the following:
controller do
def find_resource
scoped_collection.friendly.find(params[:id])
end
end