ruby-on-rails-4rails-adminrails-administrate

Rails customizing the administrate gem


I have location, concert and artist model as

class Location < ApplicationRecord
  has_many :concerts, dependent: :destroy
  has_many :artists, through: :concerts
end

class Concert < ApplicationRecord
  belongs_to :location
  belongs_to :artist
end

class Location < ApplicationRecord
  has_many :concerts, dependent: :destroy
  has_many :artists, through: :concerts
end

I'am currently using the rails administrate, now I want to customise the rails administrate gem where instead of displaying the id while adding the new concert I want to get the location and artist name there instead of there id's. I have attached the screenshot there.enter image description here


Solution

  • In your Location and Artist dashboards, you need to define a display_resource method:

    class LocationDashboard < Administrate::BaseDashboard
      def display_resource(location)
        location.name # or whatever attribute you want to use
      end
    
      # ...
    end
    

    Do the same in your Artist Dashboard and you should be good to go :)

    For more detailed info on how to customize your dashboard check this