Thank you Jaap! I thought about it previousely, but one problem exists with with validation and strong types of attributes. As i understand ProductAttribute should have several number of fields for different types of values e.g. string, decimal, integer, boolean and etc. And there should be an accessor wich will give us value from field dependent on type wich was defined in ProductDefinition. Am I right?
May be we can collaborate over this problem? On 11 авг, 15:51, jhaagmans <[email protected]> wrote: > I'm actually doing something like this right now. My example is a lot > more complex because there need to be various depths and not every > attribute is in fact an attribute, but some are a set of options, but > basically I can point you in the right direction: > > Your catalog consists of products, so you'll have a model Product. > They will have attributes, so you'll have a model ProductAttribute. > Then you'll need a table that links them together. Name it anything > you'd like, I chose ProductDefinition. Then, in the corresponding > models do: > > class Product < ActiveRecord::Base > has_many :product_definitions > has_many :product_attributes, :through => :product_definitions > end > > class ProductAttribute < ActiveRecord::Base > has_many :product_definitions > has_many :products, :through => :product_definitons > end > > class ProductDefinition < ActiveRecord::Base > belongs_to :product > belongs_to :product_attribute > end > > Now you can use eager loading to define a product: > > @product = Product.find(:first) > > And do @product.attributes to get all the product's attributes. > > Hope this helps! > > Kind regards, > Jaap Haagmans > w.http://www.relywebsolutions.nl > > On 11 aug, 11:43, insect <[email protected]> wrote: > > > > > Hello! > > > I am looking for a plugin or at least the way how to realize dynamic > > fields in a model. > > > Why I need: I want to create a product catalog application, each type > > of product can have different set of fields (e.g. computer, mobile > > phone, vacume cleaner and etc.). > > Requirements: > > 1. Set of fields with types can be defined from admin panel foreach > > product type > > 2. Validation should be presented > > 3. It should be possible to sort and filter on this fields > > 4. It should be possible to auto-generate forms for products > > > All plugins that i found does not give me this functionality. > > > Who can advise me something or point to a plugin? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

