link_to更新(没有表格)

我想要一个更新资源的链接,而不使用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来更新朋友,如下所示:
‘put’)%>

但是当Rails遇到这个链接时,他试图进入节目动作。
问题是:这样做的正确链接是什么?

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

将插入属性’data-method’设置为’put’的链接,然后由rails javascript拾取并转换为幕后forms…我想这就是你想要的。

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