在应用程序中使用自动填充function进行搜索
美好的一天。 我讨厌使用ransack按照标题查找文章的控制器。 我需要用于查找信息以使用自动完成的字段。 目前它找到了,但没有自动完成,你可以帮我解决这个问题和gemhttps://github.com/crowdint/rails3-jquery-autocomplete-app ?
的Gemfile
gem "ransack" gem 'rails3-jquery-autocomplete' gem 'nifty-generators' gem 'jquery-rails', '~> 2.0'
在视图中:
15 %>
'Search', :class=>'fl_right' %>
布局负责人:
"all" %>
调节器
class ArticlesController < ApplicationController autocomplete :article, :title
更新1和routes.rb
get 'articles/autocomplete_article_title'
在视图中更新2 ,代替<%= f.autocomplete_field :title_cont,
使用1):title_start没有更改2):articles_article_title_start等导致错误。
更新3我编辑了routes.rb。 将’articles / autocomplete_article_title’移到了locale变量的范围内, 现在它有点工作了。 ..自动完成下拉列表出现…但是空:(现在必须修复那个。
更新4尝试使用http://railscasts.com/episodes/102-auto-complete-association 。 但它适用于较旧版本的rails ……等等
更新了routes.rb中的更新5
resources :articles do get 'autocomplete_article_title' end
没有运气了。
更新6据我所知,当前的问题是:ransack和autocomplete使用一个字段。 它适用于自动填充字段类型的ransack。 但我不知道如何通过自动填充的搜索工作使字段名称可以接受。 你能帮忙吗?
更新7所以在视野中
f.text_field :title_start, "data-autocomplete" => articles_autocomplete_article_title_path, :size => 15
在routes.rb中
scope '(:locale)' do resources :users resources :news resources :articles do end get 'articles/autocomplete_article_title' get "news/index" , as: 'news' # match "/news*tail" => 'news#index' root :to => 'News#index', as: 'news' end
代替
f.autocomplete_field :title_cont, articles_autocomplete_article_title_path, :size => 15
尝试
f.text_field :title_cont, "data-autocomplete" => articles_autocomplete_article_title_path
在我的项目中,我使用了meta_search和simple_form,就像
f.input :country_name_equals, url: autocomplete_country_name_path, :as => :autocomplete
做了两件事:重新路线(先进先出,先出拳)
获取’articles / autocomplete_article_title’
得到“新闻/索引”,如:’新闻’
资源:用户
资源:新闻
资源:文章
2)重新路由控制器中的权限
skip_before_filter :authorize, except: [:edit, :update, :destroy]