ruby-on-rails – link_to更新(无表格)
发布时间:2020-12-16 20:37:56 所属栏目:百科 来源:网络整理
导读:我想要一个链接来更新资源,而不使用HTML表单. 路线: resources :users doresource :profile,:controller="profiles" resources :friendsend 耙路线: user_friend GET /users/:user_id/friends/:id(.:format){:action="show",:controller="friends"} PUT /u
我想要一个链接来更新资源,而不使用HTML表单.
路线: resources :users do resource :profile,:controller=>"profiles" resources :friends end 耙路线: user_friend GET /users/:user_id/friends/:id(.:format){:action=>"show",:controller=>"friends"} PUT /users/:user_id/friends/:id(.:format){:action=>"update",:controller=>"friends"} 我想使用put来通过一个简单的链接更新一个朋友,像这样: 但是当Rails遇到这个环节时,他试图进行演出. 解决方法link_to "Add as friend",@friend),:method=> :put 会将属性“data-method”设置为“put”的链接,这将链接到rails中,并将其转换为幕后的形式…我想这就是你想要的. 您应该考虑使用:post,因为您正在两个用户之间创建一个新的链接,而不是更新它,似乎. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |