在 Rails3 中模拟链接上的 PUT
到目前为止,我知道在 Rails 中我可以使用具有 name='_method'
和 value='put'
隐藏输入的表单来模拟 PUT 请求,但是我有兴趣模拟链接。
如何在视图中拥有适合此路线的链接:
match '/article/:id/publish', :to => 'article#publish', :via => :put
So far, I know that in Rails I can simulate a PUT request using a form which has a hidden input with name='_method'
and value='put'
, but I'm interested in simulating that for a link.
How can I have a link in a view that would fit this route:
match '/article/:id/publish', :to => 'article#publish', :via => :put
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
link_to 的文档说你可以指定一个:method 选项,用于创建单击链接时提交的表单。
不确定你的路由帮助器方法是什么(我假设
publish_article_path
- 你应该能够从命令行使用rake paths
找出它。:method
是实现您想要的魔法的重要部分。The docs for link_to say you can specify a :method option that creates a form that is submitted on clicking the link.
Not sure what your route helper method would be (I assumed
publish_article_path
- you should be able to figure it out withrake routes
from the command line. The:method
is the important part that will do the magic you want.