0
私は、リンクに関連する以下のエラーが出ますが、私の ビューで&低下を受け入れる - それはルーティングの問題だが、私はそれについて移動する方法がわからないと思います。 1は親切にこの問題 - Railsの5
エラーメッセージ
No route matches {:action=>"accept", :controller=>"friendships", :id=>"emma"}
No route matches {:action=>"decline", :controller=>"friendships", :id=>"emma"}
ビュー/ユーザー/ _friends.html.erb
<% @user.requested_friends.each do |requester| %>
<tr>
<td><%= link_to(image_tag("img-profile-image-default.png"), requester) %></td>
<td><%= link_to requester.firstname, requester %></td>
<td>
<%= link_to "Accept",
{ controller: "friendships",
action: "accept",
id: requester.firstname } %>
<%= link_to "Decline",
{ controller: "friendships",
action: "decline",
id: requester.firstname },
confirm: "Really decline friendship with #{requester.firstname}?" %>
</td>
</tr>
<% end %>
friendships_controllerを修正する方法について私に助言することができます。 rb
あなたが承諾または辞退のための任意のルートを持っていないので0
class FriendshipsController < ApplicationController
before_filter :setup_friends
def create
Friendship.request(@user, @friend)
flash[:notice] = "Friend request sent."
redirect_to :back
end
def accept
if @user.requested_friends.include?(@friend)
Friendship.accept(@user, @friend)
flash[:notice] = "Friendship with #{@friend.firstname} accepted!"
else
flash[:notice] = "No friendship request from #{@friend.firstname}."
end
redirect_to :back
end
def decline
if @user.requested_friends.include?(@friend)
Friendship.breakup(@user, @friend)
flash[:notice] = "Friendship with #{@friend.firstname} declined"
else
flash[:notice] = "No friendship request from #{@friend.firstname}."
end
redirect_to :back
end
def delete
if @user.friends.include?(@friend)
Friendship.breakup(@user, @friend)
flash[:notice] = "Friendship with #{@friend.firstname} deleted!"
else
flash[:notice] = "You aren't friends with #{@friend.firstname}"
end
redirect_to :back
end
private
def setup_friends
@user = User.find(current_user.id)
@friend = User.find_by_email(params[:id])
end
end
ルートは
Rails.application.routes.draw do
resources :friendships, only: [:create, :update, :destroy]
end
friendships POST /friendships(.:format) friendships#create
friendship PATCH /friendships/:id(.:format) friendships#update
PUT /friendships/:id(.:format) friendships#update
DELETE /friendships/:id(.:format) friendships#destroy