当我在视图中单击以下代码生成的链接时:
<%= link_to "Colleague", collaborators_path(member2_id: user.id,), :method => :post %>
我收到以下错误消息:
No route matches [GET] "/collaborators"
但是,我的路由文件中有以下行:
resources :collaborators, only: [:create, :destroy]
我在 collaborators_controller 中有以下定义:
@collaboration = current_user.collaborations.build(:member2_id => params[:member2_id])
if @collaboration.save
flash[:notice] = "Added collaborator."
redirect_to root_url
else
flash[:error] = "Unable to add collaborator."
redirect_to root_url
end
那么创建协作的路径不应该被路由器找到吗?