【问题标题】:Rails customizing the administrate gemRails 自定义管理 gem
【发布时间】:2018-11-22 09:27:51
【问题描述】:

我有地点,音乐会和艺术家模型

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

我目前正在使用 rails administrate,现在我想自定义 rails administrate gem,而不是在添加新音乐会时显示 id,我想在那里获取位置和艺术家姓名,而不是那里的 id。我已经附上了截图。

【问题讨论】:

    标签: ruby-on-rails-4 rails-admin rails-administrate


    【解决方案1】:

    在您的位置和艺术家仪表板中,您需要定义一个display_resource 方法:

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

    在您的 Artist Dashboard 中执行相同操作,您应该一切顺利 :)

    有关如何自定义仪表板的更多详细信息,请查看this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 1970-01-01
      • 2020-04-01
      相关资源
      最近更新 更多