怎么办HABTM管理与Rails的自动补全? [英] How to do HABTM management with auto completion in Rails?

查看:97
本文介绍了怎么办HABTM管理与Rails的自动补全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找在Rails的管理与HABTM关联模型的大概典型的问题很好地解决。

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

帕特肖内西正在开发修改auto_complete插件从而可以使管理一对一许多(和许多一对多)关联关系:

Pat Shaughnessy is developing modified auto_complete plugin which can allow to manage one-to-many (and many-to-many) association:

有关的人,这将是足够的,但我真的不喜欢这么多的文本字段。我想这是可能的 Ryan Ba​​tes的截屏的略有不同的方式使用专利,即使用一个文本字段与自动完成:

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.

我希望有对于现有的插件。我不是很在Ruby中有经验,真的不知道如何自己来实现这样的逻辑。

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.

任何帮助AP preciated!

Any help is appreciated!

推荐答案

这个问题可以用 jQuery的Tokeninput <很好地解决了/ A>插件,如由Ryan贝茨: http://railscasts.com/episodes/258-令牌领域

这篇关于怎么办HABTM管理与Rails的自动补全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆