如何通过PARAMS [:搜索]与autocomplete_field_tag? [英] How to pass params[:search] with autocomplete_field_tag?
问题描述
我使用的是 Crowdint Rails3中的jquery自动完成,并有我的搜索表单的麻烦。
这是怎么我的搜索
表单的外观没有自动完成:
<%=的form_tag SEARCH_PATH,:方法=> '得到'做%GT;
<%= text_field_tag:搜索,则params [:搜索]:占位符=> 搜索产品.....:ID => 主搜索领域的%GT;
<%= submit_tag搜索,:名称=>零,:ID => 主要的搜索场键%GT;
<%结束%GT;
现在,当我周围的形式自动完成和搜索改变:
<%=的form_tag SEARCH_PATH,:方法=> '得到'做%GT;
<%= autocomplete_field_tag'名','',search_autocomplete_product_name_path,则params [:搜索]:占位符=> 搜索产品.....:ID => 主搜索领域的%GT;
<%= submit_tag搜索,:名称=>零,:ID => 主要的搜索场键%GT;
<%结束%GT;
如果我有 PARAMS这将无法正常工作[:搜索]
里面我 autocomplete_field_tag
:
::的ActionView ::模板错误(错误的参数数目(5 4))
如何设置的搜索参数,所以我实际上可以自动完成?搜索
更多信息:
类SearchController< ApplicationController中
自动完成:产品:姓名,:全=>真正 #太阳黑子搜索。
高清指数
@search = Product.search做
全文PARAMS [:搜索]
分页(:per_page => 1:页=> PARAMS [:页面])
结束
@products = @ search.results
结束
结束#的routes.rb
得到的搜索/ autocomplete_product_name
资源:搜索:仅=> [:指数]
的(声明:我已经与这个特殊的宝石没有经验,下面的答案是基于一个简单的介绍一下通过它仅是源)
的 autocomplete_field_tag
方法根据源有五个参数,最后一个是一个选项哈希:
autocomplete_field_tag(名称,价值,来源,选择= {})
因此,考虑你的控制器方法如需要一个参数叫 PRODUCT_NAME
你的方法调用可能应该阅读:
autocomplete_field_tag('PRODUCT_NAME','',search_autocomplete_product_name_path,:占位符=>中搜索某个产品.....:ID =>中主搜索 - 领域)
I am using the Crowdint rails3 jquery autocomplete and having trouble with my search form.
This is how my search
form looks without autocomplete:
<%= 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%>
Now when I change around the form for autocomplete and search:
<%= 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%>
This will not work if I have params[:search]
inside of my autocomplete_field_tag
:
ActionView::Template::Error (wrong number of arguments (5 for 4))
How do I set the search parameter so I can actually search with autocomplete?
More info:
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]
(Disclaimer: I've no experience with this particular gem, the following answer is based on a brief look through it's source only.)
The autocomplete_field_tag
method takes five parameters according to the source, the last one being an options hash:
autocomplete_field_tag(name, value, source, options = {})
So, given that your controller method e.g. needs a parameter called product_name
your method call should probably read:
autocomplete_field_tag('product_name', '', search_autocomplete_product_name_path, :placeholder => "Search for a Product.....", :id => "main-search-field")
这篇关于如何通过PARAMS [:搜索]与autocomplete_field_tag?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!