简体   繁体   English

rails 3模型与rails_admin的模型关联

[英]rails 3 model associations model with rails_admin

Could some 1 help me please with associations in rails app. 可以一些帮助我与Rails应用程序中的关联。 This is my models: 这是我的模型:

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

Question is: how can i make child_catalog field look like: Catalog.name + ParentCatalog.name + ChildCatalog.name in Product edit menu... 问题是:如何使child_catalog字段看起来像:Product编辑菜单中的Catalog.name + ParentCatalog.name + ChildCatalog.name ...

Put this code in your ChildCatalog model 将此代码放入您的ChildCatalog模型中

def self.fullname
 self.parent_catelog.catelog.name + self.parent_catelog.name + self.name

end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM