Could some 1 help me please with associations in rails app. 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...
Put this code in your ChildCatalog model
def self.fullname
self.parent_catelog.catelog.name + self.parent_catelog.name + self.name
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.