I have a router:

match "/person(/:sex)(/:search)" => "person#index", :constraints => {
:sex => /male|female/ }


And a search form:

<%= form_tag("/person", :method => "get") do %>
<%= search_field_tag(:search, params[:search]) %>
<%= submit_tag("Search") %>
<% end %>


But why, after submit form url is:

http://localhost:3000/person?utf8=✓&search=Clinton&commit=Search

And not a:

http://localhost:3000/person/Clinton

or

http://localhost:3000/person/Clinton?utf8=✓&commit=Search

The "sex" is optional value and url should be only

http://localhost:3000/person/Clinton

or

http://localhost:3000/person/male/Clinton

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Frederick Cheung at Dec 11, 2011 at 10:57 am

    On Dec 11, 9:17 am, Fresh Mix wrote:
    I have a router:

    match "/person(/:sex)(/:search)" => "person#index", :constraints => {
    :sex => /male|female/ }

    And a search form:

    <%= form_tag("/person", :method => "get") do %>
    <%= search_field_tag(:search, params[:search]) %>
    <%= submit_tag("Search") %>
    <% end %>

    But why, after submit form url is:
    Your browser constructs the URL from the form. It doesn't know
    anything about routes so will always just use the URL specified in the
    form's action attribute, either appending the query string or sticking
    it in the request body depending on whether it's a get or a post.

    Fred
    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 11, '11 at 9:18a
activeDec 11, '11 at 10:57a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Fresh Mix: 1 post Frederick Cheung: 1 post

People

Translate

site design / logo © 2022 Grokbase