How to do HABTM management with auto completion in Rails?
- by Andrei
I am looking for a good solution for a probably typical problem of managing models with HABTM association in Rails.
Let's assume that we have two models -- products and categories:
Products
has_many :categorizations
has_many :categories, :through => :categorizations
Categories
has_many :categorizations
has_many :products, :through => :categorizations
Categorization
belongs_to :product
belongs_to :category
Pat Shaughnessy is developing modified auto_complete plugin which can allow to manage one-to-many (and many-to-many) association:
For someone that would be enough, but I don't really like so many text fields. I guess it is possible to combine the Ryan Bates' screencasts used by Pat in a slightly different way, namely, using one text field with autocomplete:
Also it would be better to remove from the list of suggested tasks (one-to-many), or products|categories (many-to-many) those which have been already added.
In the case of products-categories relationship, such auto completion would be used both in the form for product, and in the form for category.
I hope that there is an existing plugin for that. I am not very experienced in Ruby, and don't really know how to implement such logic by myself.
Any help is appreciated!