如何使用autocomplete_field_tag传递params [:search]?

时间:2011-11-12 19:17:15

标签: ruby-on-rails ruby ruby-on-rails-3 autocomplete

我正在使用Crowdint rails3 jquery autocomplete但我的搜索表单有问题。

这是search表单在没有自动填充的情况下的显示方式:

<%= form_tag search_path, :method => 'get' do %>
    <%= text_field_tag :search, params[:search], :placeholder => "Search for a Product.....", :id => "main-search-field" %>
    <%= submit_tag "Search", :name => nil, :id => "main-search-field-button" %>
<%end%>

现在,当我更改表单以进行自动填充和搜索时:

<%= form_tag search_path, :method => 'get' do %>
   <%= autocomplete_field_tag 'name','', search_autocomplete_product_name_path, params[:search], :placeholder => "Search for a Product.....", :id => "main-search-field" %>
   <%= submit_tag "Search", :name => nil, :id => "main-search-field-button" %>
<%end%>

如果我params[:search]内有autocomplete_field_tag

,则无效
ActionView::Template::Error (wrong number of arguments (5 for 4))

如何设置搜索参数,以便实际使用自动填充进行搜索?


更多信息:

class SearchController < ApplicationController
  autocomplete :product, :name, :full => 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]

0 个答案:

没有答案