Button_to在Ruby on Rails的坏路线 [英] Button_to in Ruby on Rails bad route
问题描述
我试图使用 button_to
导轨帮手。我写了下面code:
I'm trying to use the button_to
rails helper. I wrote the following code:
<%= button_to'编辑项目',edit_item_path(@item):类=> '标记按钮'%GT;
和得到了以下错误消息
无路由匹配/项/ 1 /编辑
但是,当我刷新页面就进入相应的操作。页面我得到的网址本地主机:3000 /项目/ 1 /编辑
这是正确的URL。如果我切换 button_to
命令的link_to
加载页面没有任何错误。这意味着code:
But when I refresh the page it goes to the appropriate action. The URL of the page i get is localhost:3000/items/1/edit
which is the correct URL. If I switch the button_to
command to link_to
the page loaded with no errors. Meaning this code:
<%=的link_to'编辑项目',edit_item_path(@item):类=> '标记按钮'%GT;
加载罚款。也许有的button_to
一些功能我不知道,但我在失落。
loads fine. Maybe there is some feature of button_to
I'm not aware of, but I am at a lost.
推荐答案
我想你可能会误用button_to。我一直认为,如果你链接到编辑动作,你应该使用的link_to。按钮似乎是需要张贴的行动/把数据如更新的形式或删除记录。
I think you might be misusing button_to. I've always thought that if you're linking to the edit action, you should be using link_to. Buttons seem to be for actions that need to post/put data such as updating a form or deleting a record.
更新:
在默认情况下,button_to使用POST而不是GET。因此,它的工作时,你只是访问URL(即GET)。
By default, button_to uses POST instead of GET. Hence it working when you just visit the URL (ie GET).
这篇关于Button_to在Ruby on Rails的坏路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!