railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.88k stars 2.25k forks source link

How to apply rails_admin for ActiveSupport::Concern used across multiple models? #2858

Open marat-chardymov opened 7 years ago

marat-chardymov commented 7 years ago

I have concern like

module FollowableModelConcern extend ActiveSupport::Concern
  included do
    has_many :followers, -> { order :created_at }, class_name: 'User', through: :followings
    has_many :followings, as: :followable, dependent: :destroy
  end
end

It is included in several of my models. How can I exclude :followings field for example from edit action? I don't want to repeat exclude code for every model

marat-chardymov commented 7 years ago

Seems like I should use rails admin config inside included:

  included do
    has_many :followers, -> { order :created_at }, class_name: 'User', through: :followings
    has_many :followings, as: :followable, dependent: :destroy

    rails_admin do
      edit do
        exclude_fields :followings
      end
    end
  end

but when I include 2 concerns into my model, only one is applied. Probably it's because exclude_fields method rewrites exclude fields array...