2017-04-23 43 views
0

我有一個Editor模型與has_many :categorieshas_many :types,通過表categories_editorseditors_types如何在rails admin中顯示關聯的名稱? (而不是id)

在管理界面中,我希望看到categories的名稱。它適用於types(請參見下圖),但是這兩種關聯的定義方式都是相同的。

enter image description here

class Editor < ApplicationRecord 
    has_many :categories_editors 
    has_many :categories, through: :categories_editors 
    has_many :editors_types 
    has_many :types, through: :editors_types 
end 

class Type < ApplicationRecord 
    has_many :editors_types 
    has_many :editors, through: :editors_types 
end 

class Category < ApplicationRecord 
    has_many :categories_editors 
    has_many :editors, through: :categories_editors 
end 

class CategoriesEditor < ApplicationRecord 
    belongs_to :editor 
    belongs_to :category 
end 

class EditorsType < ApplicationRecord 
    belongs_to :editor 
    belongs_to :type 
end 

是否有人有想法?

回答

0

爲了使您的對象的名稱顯示,你必須重命名列name

因此,我改變:

create_table "categories", force: :cascade do |t| 
    t.string "category" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    end 

到:

create_table "categories", force: :cascade do |t| 
    t.string "name" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    end 
相關問題