I'm trying to implement a search function but can't figure out what simple_form_for
needs to match up with the routes:
resources :shows do
member do
get :search
end
resources :episodes
end
I've tried a few different formats:
# 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 %>
When I place a string in the controller in place of params[:search]
the query works, so I'll leave that code out. I'm calling the form with <%= render 'search', show: @show %>
in views/shows/show.html.erb
.
Since you are expecting an object in
params[:id]
, this means its a member route and not a collection one.Change your routes file to:
Debug Hint: Always see whats the URL that is getting built (e.g. http://localhost:3000/shows/search.6?utf8=%E2%9C%93&search%5Bsearch%5D=test&commit=Search) in this case.. 6 was not getting passed in the URL correctly.. thus an issue with path helpers.