如何使用autocomplete_field_tag传递params ?
我正在使用Crowdint rails3 jquery自动完成function并且我的搜索表单有问题。
这是我的search
表单看起来没有自动完成的方式:
'get' do %> "Search for a Product.....", :id => "main-search-field" %> nil, :id => "main-search-field-button" %>
现在,当我更改表单以进行自动完成和搜索时:
'get' do %> "Search for a Product.....", :id => "main-search-field" %> nil, :id => "main-search-field-button" %>
如果我在autocomplete_field_tag
有params[:search]
,这将无效:
ActionView::Template::Error (wrong number of arguments (5 for 4))
如何设置搜索参数,以便实际使用自动完成function进行搜索?
更多信息:
class SearchController true # Sunspot search. def index @search = Product.search do fulltext params[:search] paginate(:per_page => 1, :page => params[:page]) end @products = @search.results end end # routes.rb get 'search/autocomplete_product_name' resources :search, :only => [:index]
(免责声明:我对这个特殊的gem没有经验,以下答案仅基于它的来源简要介绍。)
autocomplete_field_tag
方法根据源获取五个参数,最后一个是选项哈希:
autocomplete_field_tag(name, value, source, options = {})
因此,鉴于您的控制器方法需要一个名为product_name
的参数,您的方法调用可能应该是:
autocomplete_field_tag('product_name', '', search_autocomplete_product_name_path, :placeholder => "Search for a Product.....", :id => "main-search-field")