Ugly url form_tag

Hi all

I am using form_tag helper and everything is sent by the get method.
In the url looks like :
http://localhost:3000/posts?utf8=✓&search=rails

The utf8 attributes is pretty much ugly.

Is there a way (in Rails 3) the url looks like something like :
http://localhost:3000/posts/search/rails

If yes what do I need to change in my code ?

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 %>

Cheers
Moon

On Feb 20, 2011, at 12:03 AM, Moon Moon wrote:

If yes what do I need to change in my code ?

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.

Walter

“Posts” model has been generating via a scaffold so if I use the method
post it will correspond to the new method.

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
unless you used JavaScript to send the form request. A form has an
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
change the action. Using JavaScript, it’s trivial to rewrite the
action of the request before sending the form.

Walter