我有一个索引页面设置,它在控制器、模型和视图(Gears 模型)中有一个带有刻面设置的太阳黑子搜索。
我试图在我的应用程序的主页上放置一个不同的搜索表单(不同的视图和控制器),但我希望该表单将用户重新定向到 Gears 模型搜索结果的索引页面。现在根页面是一个没有控制器的静态页面。如何传递搜索结果并重定向视图?
我可能在想这个错误,任何帮助表示赞赏。
我的代码...
路线
Outdoor::Application.routes.draw do
resources :gears do
resources :calendars, :only => [:create, :destroy, :edit]
resources :comments, :only => [:create, :destroy]
end
match '/gear', to: "gears#index"
root to: 'pages#home'
end
控制器
class GearsController < ApplicationController
respond_to :html, :json
def index
@search = Gear.solr_search do
fulltext params[:search]
facet (:category_name)
facet (:sub_category_name)
facet (:state)
facet (:city)
facet (:price)
with(:price, params[:price]) if params[:price].present?
with(:state, params[:state]) if params[:state].present?
with(:city, params[:city]) if params[:city].present?
with(:sub_category_name, params[:name]) if params[:name].present?
with(:category_name, params[:categoryname]) if params[:categoryname].present?
paginate(page: params[:page], :per_page => 15)
end
@gears = @search.results
end
end
主页查看表单(我还没有将其更改为使用表单助手)
<form id="homesearch_form" >
<fieldset>
<input type="text" name="homesearchbox" id="homesearch_textarea" onfocus="if(this.value=='Enter the location you’d like to rent gear')this.value='';" value="Enter the location you’d like to rent gear" onblur="if(this.value=='')this.value='Enter the location you’d like to rent gear'"/>
<input type="submit" id="homesearch_submit" value="" />
</fieldset>
<fieldset id="rentaldate_home" class="form-inline">
<input type="text" name="rentaldate_home_from" id="rentaldate_home_from" onfocus="if(this.value=='From')this.value='';" value="From" onblur="if(this.value=='')this.value='From'" />
<input type="text" name="rentaldate_home_to" id="rentaldate_home_to" onfocus="if(this.value=='To')this.value='';" value="To" onblur="if(this.value=='')this.value='To'" />
</fieldset>
</form>
谢谢您的帮助。
解决了
我将主页上的表格更改为以下内容:
<%= form_tag({:controller => "gears", :action => "index"}, :method => "get", :id => "homesearch_form") do %>
<%= text_field_tag :search, params[:search], id: 'homesearch_textarea' %>
<%= submit_tag "", :name => nil, id: 'homesearch_submit' %>
<% end %>