Topic: URL parameters appear in the address bar although using post method

I'm new to ROR but I face this problem: in the index page I have
<%= button_to 'Yes', { :action => 'vote', :id => poll.id, :user_answer => 'yes' }, :method => :post  %>

when user presses the the "Yes button" the url that passed to the controller contains all the parameters explicitly to the user.

vote?id=1&user_answer=yes
in routes.rb I have:

match 'vote' => 'polls#vote', :via => :post
Any help is appreciated

edit: the entire index.html.erb

Polls

<% @polls.each do |poll| %>
   <p>
   <%= poll.question %>?
   <%= button_to 'Yes', { :action => 'vote', :id => poll.id, :user_answer => 'yes' }, :method => :post %> (<%= poll.yes %>) /
   <%= button_to 'No', { :action => 'vote', :id => poll.id, :user_answer => 'no' }, :method => :post %> (<%= poll.no %>)
   </p>
<% end %>

Last edited by mina (2012-08-21 17:23:59)

Re: URL parameters appear in the address bar although using post method

View the source, is the form a GET method? Also look at the form's action url, is it /vote like you're wanting it to be in routes.rb?

Also, a refactor tip, use

post 'vote' => 'polls#vote'

instead of what you have. It does the exact same thing

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!