URL parameters are displayed in the address bar, but when using POST

I am new to ROR, but am facing this problem: on the index page I have

<%= button_to 'Yes', { :action => 'vote', :id => poll.id, :user_answer => 'yes' }, :method => :post %> 

when the user clicks Yes, the URL passed to the controller contains all the parameters explicitly for the user.

 vote?id=1&user_answer=yes 

in routes.rb I have:

 match 'vote' => 'polls#vote', :via => :post 

Any help is appreciated

edit: whole 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 %> 
+4
source share
1 answer

The button_to method is post by default, so there is no need to explicitly specify it if you do not want to use other verbs (get, put).

If you don't like the options added to the URL, you can use the form instead.
Or just add the form hash to the button_to tag:

 <%= button_to 'Yes', { :action => 'vote', :id => poll.id, :user_answer => 'yes' }, :form => {:data_type => <your choice (html, json)> %> 
0
source

All Articles