Rails3 jquery自动完成不同的值

the*_*sis 4 jquery autocomplete jquery-autocomplete ruby-on-rails-3

是否可以使用Rails3 JQuery自动完成宝石选择DISTINCT值?

che*_*ech 9

使用范围更好,更简单.

在你的模型中:

scope :uniquely_named, group(:name)
Run Code Online (Sandbox Code Playgroud)

在你的控制器中:

autocomplete :user, :name, :scopes => [:uniquely_named]
Run Code Online (Sandbox Code Playgroud)

该解决方案允许更轻松地应用更复杂的过滤:

模型:

scope :uniquely_named, group(:name)
scope :online, where(:online => true)
Run Code Online (Sandbox Code Playgroud)

控制器:

autocomplete :user, :name, :scopes => [:uniquely_named, :online]
Run Code Online (Sandbox Code Playgroud)

资源