Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do HABTM management with auto completion in Rails?
    text
    copied!<p>I am looking for a good solution for a probably typical problem of managing models with HABTM association in Rails.</p> <p>Let's assume that we have two models -- products and categories:</p> <pre><code>Products has_many :categorizations has_many :categories, :through =&gt; :categorizations Categories has_many :categorizations has_many :products, :through =&gt; :categorizations Categorization belongs_to :product belongs_to :category </code></pre> <p>Pat Shaughnessy is developing <a href="http://www.github.com/patshaughnessy/auto_complete" rel="nofollow noreferrer">modified auto_complete plugin</a> which can allow to manage one-to-many (and many-to-many) association:</p> <p><a href="http://img28.imageshack.us/i/samplef.png/" rel="nofollow noreferrer">alt text http://img28.imageshack.us/img28/9141/samplef.th.png</a> <a href="http://img406.imageshack.us/i/sampleautocomplete.png/" rel="nofollow noreferrer">alt text http://img406.imageshack.us/img406/4075/sampleautocomplete.th.png</a></p> <p>For someone that would be enough, but I don't really like so many text fields. I guess it is possible to combine the <a href="http://railscasts.com/" rel="nofollow noreferrer">Ryan Bates' screencasts</a> used by Pat in a slightly different way, namely, <strong>using one text field</strong> with autocomplete:</p> <p><a href="http://img405.imageshack.us/i/betterautocomplete.png/" rel="nofollow noreferrer">alt text http://img405.imageshack.us/img405/9576/betterautocomplete.th.png</a></p> <p>Also it would be better <strong>to remove</strong> from the list of suggested tasks (one-to-many), or products|categories (many-to-many) those which have been <strong>already added</strong>.</p> <p>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.</p> <p>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.</p> <p>Any help is appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload