2017-10-09 110 views
0

我试图创建一个简单的搜索表单,将用户转移到单独的“结果”页面。路由一个简单的搜索表单

我对index.html.erb示意如下:

<%= simple_form_for results_path, method: :get, html: { class: "form-inline justify-content-center" } do |f| %> 

    <%= f.select :what, options_for_select([['Happy Hours Anywhere','Anywhere'],['After Work Drinks','After Work Drinks'],['Somewhere to Relax with Friends', 'Relaxing with Friends'], ['A Club Night','Club Night'], ['Somewhere for Date Night','Date Night'], ['A Place to Watch Sports', 'Watching Sports']]),{} ,:class => "form-control select-box font-lightweight" %> 

    <%= f.select :datetime, options_for_select(dates_for_search_select.each_with_index.map{|d, i| [d[1],d[0]]}), {}, :class => "form-control select-box font-lightweight" %> 

    <%= f.select :time, options_for_select(times_for_search_select.each_with_index.map{|d, i| [d[1],d[0]]}), {}, :class => "form-control select-box font-lightweight" %> 

    <%= f.button :submit, 'Discover', :class => 'btn btn-block btn-danger btn-embossed top-margin ' %> 
<%end%> 

我已经创建了我的 '结果' 路线,可以看到下面:

Rails.application.routes.draw do 
    resources :offers 
    resources :venues 
    get 'home/results' => 'home#results', :as => :results 
    get 'home/index' 
    devise_for :users 
    root to: "home#index"  
end 

然而,当我生成HTML产生的形式行动保持路由回索引页:

<form class="simple_form form-inline justify-content-center" novalidate="novalidate" 
action="/home/index" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓"> 

</form> 

我在想什么?

+0

尝试用此得到“成果”,到:“家#结果” –

回答

0

simple_form_for要求将对象作为第一个参数(类实例或符号)。那么您可以添加url: articles_path,就像正常的form_for一样。见simple form source code

所以,你需要有一个行是这样的:

<%= simple_form_for :results, url: results_path, method: :get, html: { class: "form-inline justify-content-center" } do |f| %>