加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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来通过一个简单的链接更新一个朋友,像这样:
<%= link_to“添加为朋友”,user_friend_path(current_user,:method =>‘put’)%>

但是当Rails遇到这个环节时,他试图进行演出.
问题是:这是正确的链接?

解决方法

link_to "Add as friend",@friend),:method=> :put

会将属性“data-method”设置为“put”的链接,这将链接到rails中,并将其转换为幕后的形式…我想这就是你想要的.

您应该考虑使用:post,因为您正在两个用户之间创建一个新的链接,而不是更新它,似乎.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读