有些人可以通过rails app中的协会帮助我。这是我的模特:
class Catalog < ActiveRecord::Base
attr_accessible :name
has_many :parent_catalogs
end
class ParentCatalog < ActiveRecord::Base
attr_accessible :catalog_id, :name
has_many :child_catalogs
belongs_to :catalog
end
class ChildCatalog < ActiveRecord::Base
attr_accessible :name, :parent_catalog_id
has_many :products
belongs_to :parent_catalog
end
class Product < ActiveRecord::Base
attr_accessible :child_catalog_id, :name
belongs_to :child_catalog
# Ex
rails_admin do
field :name
field :child_catalog do
# How ((
end
end
end
问题是:如何使child_catalog字段看起来像: Catalog.name + ParentCatalog.name + ChildCatalog.name 在产品编辑菜单中......
答案 0 :(得分:0)
将此代码放入ChildCatalog模型
def self.fullname
self.parent_catelog.catelog.name + self.parent_catelog.name + self.name
end