0

I have ActiveAdmin set up to manage the users on the site, and Friendly_id for readable urls. When I go to /admin/users, it throws this error:

Undefined method `per' for #<User::FriendlyIdActiveRecordRelation:0x007fdb61a38d30>

How friendly_id is set up in the user model:

class User < ActiveRecord::Base
  #...
  extend FriendlyId
  friendly_id :name, use: :slugged
end

The only resource I could find for the conflict between these 2 gems is this question ActiveRecord::ReadOnlyRecord when using ActiveAdmin and Friendly_id which seems like a different issue and the solution doesn't work in my case. Any suggestions on how to resolve this?

Community
  • 1
  • 1
Ryan Dao
  • 321
  • 1
  • 4
  • 13

3 Answers3

2

I was able to fix it 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
Jason Swett
  • 43,526
  • 67
  • 220
  • 351
0

I figured out that it's actually not the problem with friendly_id but with will_paginate as mentioned here https://github.com/gregbell/active_admin/issues/670. Switching to kaminari for pagination solves the issue for me.

Ryan Dao
  • 321
  • 1
  • 4
  • 13
0

I also encountered this issue, and found that friendly_id overrides the to_param method, so just re-override it. it works for me.

ActiveAdmin.register User do
  before_filter do
    User.class_eval do
      def to_param
        id.to_s
      end
    end
  end
end
Boyi
  • 120
  • 4