1

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.

4

1 回答 1

2

尝试这个

<%= button_to "delete", {:controller => :static_pages, :action => 'fresh'}, :method => :get %>

还要检查您的 routes.rb 以确保定义了新的路由。

于 2013-04-26T02:36:22.687 回答