ビューで次のコードによって生成されたリンクをクリックすると、次のようになります。
<%= link_to "Colleague", collaborators_path(member2_id: user.id,), :method => :post %>
次のエラーメッセージが表示されます。
No route matches [GET] "/collaborators"
ただし、routesファイルには次の行があります。
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
では、コラボレーションを作成するためのパスをルーターが見つけてはいけませんか?