一直试图解决这个问题,但无法弄清楚我做错了什么。我只是想破坏两个用户之间的友谊。
视图如下所示:
友谊/index.html.erb
<% @users.each do |user| %>
<% if user.id != current_user.id %>
<%=h user.name %>
<%if current_user.is_friend? user %>
<%= link_to "Destroy", friendships_path(:friend_id => user), :method => :delete %>
<%else%>
<%= link_to "Add friend", friendships_path(:friend_id => user), :method => :post %>
<% end %>
<% end %>
<% end %>
友谊控制器
def index
@users = User.all
end
def show
@user = current_user
end
def create
@friendship = current_user.friendships.build(:friend_id => params[:friend_id])
if @friendship.save
flash[:notice] = "Added friend."
redirect_to root_url
else
flash[:error] = "Error occurred when adding friend."
redirect_to root_url
end
end
def destroy
@friendship = current_user.friendships.find(params[:id])
@friendship.destroy
flash[:notice] = "Successfully destroyed friendship."
redirect_to root_url
end
我收到此错误:
没有路线匹配 [DELETE] "/friendships"
但是,当我运行 rake 路线时,我似乎有路径:
friendship GET /friendships/:id(.:format) friendships#show
PUT /friendships/:id(.:format) friendships#update
DELETE /friendships/:id(.:format) friendships#destroy