2017-09-14 3 views
0

なぜこれで現在のユーザーがユーザーをフォローできないのか分かりません。 "アンフォロー" ボタンをクリックすると、ページがに/友情ルーティングされます= 2 friend_idと、このエラーメッセージ:?Noルートの試合は "/友情" [削除]をRuby on Rails:ユーザーをフォローしない

_user.html.erb

<%= link_to "Unfollow", friendships_path(friend_id: user.id), method: :delete, data: { confirm: "Are you sure?" }, class:"btn btn-md btn-danger" %> 
を表示されます

友情コントローラ

def destroy 
    @friendship = Friendship.find_by(id: params[:id]) 
    @friendship.destroy 
    flash[:notice] = "Removed friendship." 
    redirect_back fallback_location: root_path 
end 

routes.rbを

resources :friendships, only: [:create, :update, :destroy] 

schema.rb

create_table "friendships", force: :cascade do |t| 
    t.integer "user_id" 
    t.integer "friend_id" 
    t.boolean "accepted", default: false 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    end 

答えて

1

ます(friendships_path)

<%= link_to "Unfollow", friendship_path(current_user.friendships.find_by_friend_id(u‌​ser.id)), :method => :delete, data: { confirm: "Are you sure?" }, class:"btn btn-md btn-danger" %> 
単数friendship_pathない複数形を使用して試すことができます