2013-07-19 112 views
0

有一個1可以幫助我與rails應用協會。這是我的模型:rails 3模型協會與rails_admin模型

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

將這個代碼在您的ChildCatalog模型中

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

end 
+0

許多thx回覆。 但沒有運氣那= =( –