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=%E2%9C%93&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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 20, 2011, at 12:03 AM, Moon Moon wrote:> 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=%E2%9C%93&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 %> >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> > Cheers > Moon > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
"Posts" model has been generating via a scaffold so if I use the method post it will correspond to the new method. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Feb 20, 2011, at 8:49 PM, Moon Moon wrote:> "Posts" model has been generating via a scaffold so if I use the > method > post it will correspond to the new method. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.