Reputation: 265
This should be an easy question, but I just can't figure it out. I want to trigger an action (which just renders a page) through a button using "button_to" in view:
<%= button_to "Fresh", action: 'fresh', method: 'get' %>
The error says "No route matches [POST] "/static_pages/fresh"". It seems that the button still uses "post" instead the "get". Meanwhile, if I use "link_to", it works fine.
<%= link_to "Fresh", action: 'fresh', method: 'get' %>
Thanks for any comments and help.
Upvotes: 1
Views: 2314
Reputation: 1545
Try this
<%= button_to "delete", {:controller => :static_pages, :action => 'fresh'}, :method => :get %>
Also check your routes.rb to ensure that the route to fresh is defined.
Upvotes: 2