2012-09-05 59 views
0

我想建立一個友誼系統sorta以下鏈接:如何在社交網絡應用程序的Rails 3中實現友誼模型?但缺乏一點。我能夠建立關係,但我不確定如何執行以下操作:取消,拒絕,接受。Rails友誼取消,拒絕

所以,可以說,我嘗試取消的關係,我不上掛起以下,叫我做後續動作:

<% @customer.pending_friends.each do |pf| %> 
    <%= link_to pf.incomplete_name, cancel_friendships_path(:friend_id => pf), :method => :post %><br /> 
<% end %> 

這裏的控制器取消

def cancel 
    @customer = current_customer 
    @friend = Customer.find(params[:friend_id]) 
    if @customer.pending_friends.include?(@friend) 
     Friendship.breakup(@customer, @friend) 
     flash[:notice] = "Friendship Canceled" 
    else 
     flash[:notice] = "No Friendship request" 
    end 
    redirect_to root_url 
    end 

和這裏我的分手功能

# Delete a friendship or cancel a pending request. 
    def self.breakup(customer, friend) 
    transaction do 
     destroy(find_by_customer_id_and_friend_id(customer, friend)) 
     destroy(find_by_customer_id_and_friend_id(friend, customer)) 
    end 
    end 

但是,當我點擊c ancel鏈接。我做錯了什麼?

這裏就要求

route.rb

resources :friendships do 
    collection do 
     get 'cancel' 
     get 'decline' 
    end 
    end 
    resources :friendships 

耙路線

  cancel_friendships GET /friendships/cancel(.:format)      friendships#cancel 
     decline_friendships GET /friendships/decline(.:format)      friendships#decline 
          GET /friendships(.:format)        friendships#index 
          POST /friendships(.:format)        friendships#create 
          GET /friendships/new(.:format)       friendships#new 
          GET /friendships/:id/edit(.:format)      friendships#edit 
          GET /friendships/:id(.:format)       friendships#show 
          PUT /friendships/:id(.:format)       friendships#update 
          DELETE /friendships/:id(.:format)       friendships#destroy 

/********************************************************/ 


       friendships GET /friendships(.:format)        friendships#index 
          POST /friendships(.:format)        friendships#create 
       new_friendship GET /friendships/new(.:format)       friendships#new 
      edit_friendship GET /friendships/:id/edit(.:format)      friendships#edit 
        friendship GET /friendships/:id(.:format)       friendships#show 
          PUT /friendships/:id(.:format)       friendships#update 
          DELETE /friendships/:id(.:format)       friendships#destroy 
+0

你可以發佈你的'routes.rb'和'rake routes'的輸出嗎? – Mischa

+0

只需添加它! – Jseb

回答

1

的問題是,在你的路由你必須:

get 'cancel' 

但你取消鏈接是doi一個郵寄請求,而不是一個得到:

<%= link_to ..., ..., :method => :post %> 

我個人認爲它應該是一個刪除請求。

在你的路線:

delete 'cancel' 

在你看來:

<%= link_to pf.incomplete_name, cancel_friendships_path(:friend_id => pf), :method => :delete %> 

您的代碼可能有其他的問題,但是這是你必須解決的一件事。