我应该使用什么URL来进行更新? [英] What URL should I use to PUT an update?
问题描述
我有一个我刚拿起的Rails应用程序在rake routes中有以下命令:
I have a Rails app that I just picked up that has the following command in "rake routes":
PUT /testclass/:id(.:format) testclass#update
我想向此发送PUT更新 testclass
, id
18445并将已完成
更改为false:
I want to send a PUT update to this testclass
with the id
18445 and change finished
to false:
/18445&finished=false
$ b例如
$ b
。
for example.
我的理解是这应该可以通过浏览器中的HTTP请求来完成,例如,它可以吗?或者我需要使用Ruby命令吗?
任何指导?
My understanding is this should be able to be done by a HTTP request in the browser, for example, can it? Or do I need to use a Ruby command? Any guidance?
推荐答案
您不需要使用ruby命令来访问该路由以进行更新。
You do not need to use a ruby command to access that route to make an update.
基本HTML看起来像这样(你可以编辑与你的路线相关的动作):
Basic HTML will look something like this (you can edit the action to be relevant to your route):
<form action='testclass/18445' method="post">
<input type="hidden" name="_method" value="put">
<input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden">
<input type="hidden" name="testclass[id]" value="18445" >
<input type="hidden" name="testclass[finished]" value="false" >
<input type="submit" value="update" >
</form>
注意它是一个帖子,但有一个名为'_method'和值的隐藏输入'放'。希望这是你正在寻找的。您可以通过隐藏输入发送您的ID,与false值相同。
Notice it is a 'post' but there is a hidden input with the name '_method' and value 'put'. Hopefully this is what you're looking for. You can send your id through a hidden input, same with the false value.
这篇关于我应该使用什么URL来进行更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!