I have a site built using the railstutorial as a template. I have added a search controller to allow me to perform site searches and redirect the user to a search view. When I go to the path '/search' it is as expected (no results) but if I actually use the search input box I get logged out and have to log back in. What would be causing this?
My form:
<form action="/search" method="POST" class="navbar-search pull-right">
     <input name="query" type="text" class="search-query" placeholder="Search">
 </form>
 My search controller:
class SearchController < ApplicationController
     def index
         unless params[:query].nil?
             @results = ThinkingSphinx.search params[:query]
         else
             @results = []
         end
     end
 end
 My view:
<% unless @results.empty? %>
     <table class="table">
         <% @results.each do |result| %>
             <tr>
                 <% if result.class.name == "Event" %>
                     <td><%= link_to result.name, organisation_event_path(result.organisation, result.slug) %></td>
                     <td><%= result.summary %></td>
                 <% end %>
             </tr>
         <% end %>
     </table>
 <% else %>
     <p>No results found.</p>
 <% end %>
 My route:
match '/search', to: 'search#index'
 
Change your method from "POST" to "GET" and it will work
ReplyDelete