2012-03-03 70 views
0

使用此gem來添加私人消息到我的應用程序。如何銷燬多態模型?方法銷燬缺少的參數

https://github.com/LTe/acts-as-messageable/blob/master/lib/acts-as-messageable/message.rb

我真的試圖刪除鏈接添加到消息。

所以在我的控制,我有破壞作用:

def destroy 
    @message = current_user.messages.with_id(params[:id]) 
    if @message.destroy 
     flash[:notice] = "All ok" 
    else 
     flash[:error] = "Fail" 
    end 
    end 

在我看來,我有鏈接:= link_to "Delete", message_path(message.id), :method => :delete

但是,當我嘗試點擊鏈接我得到:wrong number of arguments (0 for 1)

這是與此問題相關:Why delete method gives me wrong path? with

回答

1

問題是你得到全部消息,所以@message確實是多個消息。你可能想這樣做:

@message = Message.find(params[:id]) 

但這可能是不同的寶石。 gem's documentationreadme的底部有刪除部分。

+0

我把它改成'''@message = current_user.messages.with_id(params [:id])。first''' – tomekfranek 2012-03-03 21:56:37

+0

@regedarek是的,這可能會有相同的效果,因爲'current_user.messages.with_id params [:id])。size'可能是'1'。 – 2012-03-03 22:27:02