我正在尝试实现搜索功能,但无法弄清楚simple_form_for
需要与路线匹配的内容:
resources :shows do
member do
get :search
end
resources :episodes
end
我尝试了几种不同的格式:
# views/shows/_search.html.erb
<%= simple_form_for :search, url: search_show_path(show), :method => :get do |f| %>
<%= f.input :search %>
<%= f.button :submit, "Search", class: "btn btn-default" %>
<% end %>
<%= simple_form_for search_show_path(show), :method => :get do |f| %>
<%= f.input :search %>
<%= f.button :submit, "Search", class: "btn btn-default" %>
<% end %>
<%= simple_form_for search_show_url(show), :method => :get do |f| %>
<%= f.input :search %>
<%= f.button :submit, "Search", class: "btn btn-default" %>
<% end %>
当我在控制器中放置一个字符串来代替params[:search]
查询时,我将忽略该代码。我用<%= render 'search', show: @show %>
in调用表格views/shows/show.html.erb
。