Hi everybody, I'm using ruby 1.9.1, with rails 2.3.*. I have an application of products and categories, but I want each type of product to have specific attributes. So, basically, according to the chosen category, I want different fields to be shown for the user.
So, before actually making the association of the product with the attribute, I want to create an administration system where the administrators could actually select wich fields they want for each category, in an N:N association, usign has many through (categoryFields is the middle table). So, up to now, the structure is: class Field < ActiveRecord::Base has_many :categoryFields, :dependent => :destroy has_many :categories, :through => :categoryFields end class CategoryField < ActiveRecord::Base belongs_to :field belongs_to :category end class Category < ActiveRecord::Base has_many :categoryFields, :dependent => :destroy has_many :fields, :through => :categoryFields end And this works perfectly. so, now, in my Category Edit view, I want to show a list of ALL AVAILABLE FIELDS (i.e. only those not already associated to that specific category) at the right, and in the left, all the ASSOCIATED FIELDS for that category. Using a simple drag-and-drop, the user can drag fields from the right to insert them in category, or move them to the right to remove them from that specific category. The problem is that I don't want that any field in the left column also appear in the right column (each field can only be used once in that specific category, since those attributes are unique). So, once you have associated a field to a category, it will not appear in the list of available fields (right list). I'm coming from PHP and this is my first rails application (I know, it's kinda complicated for a noob). So, what should I do, to exclude those values? The edit method in the category controller: @category = Category.find(params[:id]) @categories = Category.roots #the categories acts as nested set, so we have to fetch all available parent categories @fields = Field.all Now, the view do the following: <div class="category_fields span-12 last"> <% if !...@category.fields.empty? # this loops through all teh ASSOCIATED fields and display their names%> <% @category.fields.each do |field| %> <%=field.name%> <% end %> <% end %> </div> <div class="fields_available"> <% if !...@fields.empty? # this loops through ALL THE fields and display their names %> <% @fields.each do |field| %> <%=field.name%> <% end %> <% end %> </div> So, where should I place the "filter" so that only available fields will appear in the second div? Shoud I place it in the controller, as a condition somehow, and how? Or should I use some array-function to "pop out" the already associated fields from the @fields array? Wich is better from the point of view of performance, and how do I do each of them? Thanks a lot in advice, for any help Samuel Brandão w...@samuelbrandao.com.br -- 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 rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.