无形式创造
我正在尝试创建一个没有表单的对象,但只需单击一个链接:
<%=link_to "Add as friend", user_friend_path(current_user,u), :method=>:post %>
Friend 是用户内部的嵌套资源,在此链接中,current_user 是用户,u 将成为朋友。
当我点击它时,出现以下错误:
Routing Error
No route matches "/users/101/friends/86"
有人可以帮助我吗?
I'm trying to create an object without a form, but just clicking on a link:
<%=link_to "Add as friend", user_friend_path(current_user,u), :method=>:post %>
Friend is a nested resource inside the user, in this link, current_user is the user and u will be the friend.
When I click on it, the following error appear:
Routing Error
No route matches "/users/101/friends/86"
Someone can help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能正在尝试创建友谊,因此您的路径助手应该为连接(也许是friendships_path?)模型创建路径。
添加
我猜您正在使用连接模型来建立友谊?如果是这样,创建链接“添加为朋友”可能应该为此模型的表创建一个条目,对吧?因此,您的链接需要指向此连接模型的正确路径,而不是嵌套的用户/朋友路径。但同样,我只是猜测,因为我不知道你的型号。
Your probably trying to create a friendship, so your path helper should create the path for the join (friendships_path maybe?) model rather.
Addition
I'm guessing that you're using a join model for your friendships? If so the create link "Add as friend" should probably create an entry for this model's table, right? So your link needs to point to proper path for this join model, not the nested user/friend path. But again, I'm just guessing, since I don't know your models.