2

I install rails admin and include all model in active record in rails admin,

first time, when install rails admin display me this error

NoMethodError in RailsAdmin::MainController#index

undefined method `per_page_kaminari' for #<ActiveRecord::Relation:0x00000006713e18>

and fixed it by added this configure

Kaminari.configure do |config|
    config.page_method_name = :per_page_kaminari
end

when install acts_as_taggable_on gem in project, rails admin did't add tag model in it ( i added field tags_list in other model), but i want to add tag model in rails admin to manage tags (index,create,edit and destroy)..

I added this line

config.included_models = ['ActsAsTaggableOn::Tag'] 

in rails_admin.rb and it display me tag model in dashboard, but when open list tags, it display me again this error

NoMethodError in RailsAdmin::MainController#index

undefined method `per_page_kaminari' for #<ActiveRecord::Relation:0x00000006713e18>

what should i do to add tag model in rails admin and manage tags ?!

1

3 Answers 3

4

I had to solve the same issue here. I used the gem 'rails_admin_tag_list' but latest version from rubygem is not updated for rails 4 (doesnt support RailsAdmin Property). So you need to get the one from master that include the fix.

gem 'rails_admin_tag_list', git: 'https://github.com/kryzhovnik/rails_admin_tag_list.git', branch: 'master'

Indeed add:

config.included_models = ['YourModel', 'ActsAsTaggableOn::Tag']

and

class YourModel < ActiveRecord::Base
  acts_as_taggable # dont add attr_accessible stuff since we're in rails 4
end

then choose the config for tag list:

config.model 'YourModel' do
  configure :tag_list  do
    partial 'tag_list_with_autocomplete'
  end
  exclude_fields :body, :locale, :base_tags, :tags
end
0
2

The exact same issue occurs with ActiveAdmin: Manage acts_as_taggable tags with activeadmin. I solved it with the same solution:

Add an initializer to config/initializers with the custom Kaminari code:

Kaminari.configure do |config|
    config.page_method_name = :per_page_kaminari
end

Create a new class in app/models called tag.rb:

# This class fixes a bug between Kaminari, RailsAdmin, and ActsAsTaggableOn.
class Tag < ActiveRecord::Base
end

Use the Tag model instead of ActsAsTaggableOn::Tag in RailsAdmin config:

config.included_models = [Tag] 
1
  • I am new in ruby and rails so i am still understading the data flow and architecture. My question is how rails_addmin (and ActiveAdmin too) was able to grab the information from the ActsAsTaggableOn::Tag model? Oct 23, 2021 at 16:38
2

Here's my solution with rails 4 and fields configuration (must be before the congig.included_models call):

config.model ActsAsTaggableOn::Tag do 
    edit do 
      exclude_fields :taggings_count
      exclude_fields :taggings
    end
  end

  config.model ActsAsTaggableOn::Tagging do 
    edit do 
      exclude_fields :context
    end
  end

  admin_models = ActiveRecord::Base.descendants.map(&:name)
  admin_models.delete("PgSearch::Document") #if you use it
  admin_models.delete("PaperTrail::Version") #if you use it
  #add other models to exclude here
  config.included_models = admin_models

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.