2017-04-23 12 views
0

has_many :categorieshas_many :typesEditorモデルをテーブル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 

誰かがアイデアを持っていますか?あなたのコラムname

の名前を変更する必要が表示され、あなたのオブジェクトの名前を持つように

答えて

0

は、だから私は変更:

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 
関連する問題