How to do HABTM management with auto completion in Rails?
Posted
by Andrei
on Stack Overflow
See other posts from Stack Overflow
or by Andrei
Published on 2009-10-02T17:42:24Z
Indexed on
2010/05/15
19:04 UTC
Read the original article
Hit count: 265
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!
© Stack Overflow or respective owner