Tuesday, October 6, 2009

Be careful with button_to in RESTful routes


# This will be default use POST method which in this context be sent as a create resource
<% form_for @course do |f| %>
...
<% end %>
<%= button_to 'Cancel', courses_path %>

# Specify GET method explicitly so it will call index resource instead
<%= button_to 'Cancel', courses_path, :method => :get %>

No comments:

Blog Archive