簡體   English   中英

rails 3模型與rails_admin的模型關聯

[英]rails 3 model associations model with rails_admin

可以一些幫助我與Rails應用程序中的關聯。 這是我的模型:

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字段看起來像:Product編輯菜單中的Catalog.name + ParentCatalog.name + ChildCatalog.name ...

將此代碼放入您的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