Here is my code
<% form_tag posts_path, :method => ‘get’, :class => “mainsearch” do %>
<%= text_field_tag :search, params[:search], :class => “keyword” %>
<%= submit_tag ‘’,:class => “submit” %>
<% end %>
Just change :method => ‘get’ to :method => ‘post’ and you’ll have a
cleaner search. But using GET for a search is actually a good idea,
because it allows the results to be bookmarked or shared. Ugly,
perhaps. But still useful.
Ok, well in that case, do the URL to the proper controller method.
Instead of using posts_path, make a complete URI for the method you
want to hit. The only reason that your POST method request to the
posts_controller is ending up on the new method is because you’re not
sending an unambiguous request, so REST is taking over.
Looking back at your original request, you wanted to be sending a GET
request that looked like posts/search/rails, where rails was a query
term. I’m not sure how you could send that request in the first place
action, and that’s fixed, not modified by the contents of the form’s
elements. The body of the form request contains all of the elements
and their values at the time the form was submitted. But that doesn’t
action of the request before sending the form.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.