如何销毁多态模型?方法销毁缺少的参数 [英] How to destroy polymorphic model? Method destroy missing argument

查看:34
本文介绍了如何销毁多态模型?方法销毁缺少的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个 gem 向我的应用程序添加私人消息.

Im using this gem to add private messages to my application.

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

我正在尝试为消息添加删除链接.

I`m trying to add remove link to message.

所以在我的控制器中我有销毁操作:

So in my controller i have destroy action:

  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 =>:删除

但是当我尝试单击链接时,我收到:参数数量错误(0 代表 1)

But when im trying to click link i receive: wrong number of arguments (0 for 1)

这与这个问题有关:为什么删除方法给出我走错路了?与

推荐答案

问题是您收到所有消息,所以 @message 实际上是多条消息.您可能想要这样做:

The problem is that you're getting all messages, so @message is really multiple messages. You probably want to do:

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

但这对于宝石来说可能有所不同.gem 的文档 在底部有一个关于删除的部分自述文件.

But this may be different for the gem. The gem's documentation has a section on deleting at the bottom of the readme.

这篇关于如何销毁多态模型?方法销毁缺少的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆