我正在寻找一个好的解决方案来解决 Rails 中使用 HABTM 关联管理模型的可能典型问题。
假设我们有两个模型——产品和类别:
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
帕特·肖内西正在发育修改auto_complete插件 http://www.github.com/patshaughnessy/auto_complete它可以允许管理一对多(和多对多)关联:
替代文本http://img28.imageshack.us/img28/9141/samplef.th.png http://img28.imageshack.us/i/samplef.png/ 替代文本 http://img406.imageshack.us/img406/4075/sampleautocomplete.th.png http://img406.imageshack.us/i/sampleautocomplete.png/
对于某些人来说这已经足够了,但我不太喜欢这么多文本字段。我想可以结合瑞安·贝茨的截屏视频 http://railscasts.com/帕特以稍微不同的方式使用,即使用一个文本字段具有自动完成功能:
替代文本http://img405.imageshack.us/img405/9576/betterautocomplete.th.png http://img405.imageshack.us/i/betterautocomplete.png/
还有这样会更好去除从建议任务(一对多)或产品|类别(多对多)列表中已经加入.
在产品-类别关系的情况下,这种自动完成将同时用在产品表单和类别表单中。
我希望有一个现有的插件可以实现这一点。我对 Ruby 的经验不是很丰富,也不知道如何自己实现这样的逻辑。
任何帮助表示赞赏!