Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails4偏执狂2垃圾箱的实施_Ruby On Rails_Ruby On Rails 4_Recycle Bin_Acts As Paranoid - Fatal编程技术网

Ruby on rails Rails4偏执狂2垃圾箱的实施

Ruby on rails Rails4偏执狂2垃圾箱的实施,ruby-on-rails,ruby-on-rails-4,recycle-bin,acts-as-paranoid,Ruby On Rails,Ruby On Rails 4,Recycle Bin,Acts As Paranoid,问题解决了,不在我指责的Rails路由器上。我希望把这篇文章留给那些想用paranoid2 gem实现垃圾桶功能的人 我正在使用paranoid2 gem(类似于paranoid,但适用于Rails4)来保护我的数据不被意外删除,效果很好,我正在尝试为我的应用程序创建垃圾。它应该显示标记为已删除(完成)的内容,给出恢复数据(todo)的方法,永久删除(完成)并清空整个垃圾箱(这就是问题所在) 以下是我的路线,效果良好: trash_index GET /trash(.:format)

问题解决了,不在我指责的Rails路由器上。我希望把这篇文章留给那些想用paranoid2 gem实现垃圾桶功能的人

我正在使用paranoid2 gem(类似于paranoid,但适用于Rails4)来保护我的数据不被意外删除,效果很好,我正在尝试为我的应用程序创建垃圾。它应该显示标记为已删除(完成)的内容,给出恢复数据(todo)的方法,永久删除(完成)并清空整个垃圾箱(这就是问题所在)

以下是我的路线,效果良好:

trash_index GET    /trash(.:format)                       trash#index
      trash GET    /trash/:id(.:format)                   trash#show
            DELETE /trash/:id(.:format)                   trash#destroy
我还有一个,但它不能像我想要的那样工作:

all_trash_index DELETE /trash/all(.:format)                   trash#destroy_all
对我来说看起来不错,因为它使用DELETE,不需要:id参数,应该路由到trash#destroy(我在trash#controller.rb中的所有内容):

    def destroy_all
        [..]
    end

    def destroy
        [..]
    end
def destroy_all
  if Slide.only_deleted.map(&destroy(force: true))
  [..]
但当我试图到达那里时,我最终会出错:

Started DELETE "/trash/all"
Processing by TrashController#destroy_all as HTML
  Parameters: {"authenticity_token"=>"..."}
Completed 500 Internal Server Error in 11ms

ArgumentError (wrong number of arguments (1 for 0)):
  app/controllers/trash_controller.rb:15:in `destroy'
  app/controllers/trash_controller.rb:8:in `destroy_all'
为什么我会以“销毁”动作结束?。并且销毁和销毁都有错误

这是我的路线。rb:

resources :trash, only: [:index, :show, :destroy] do
    match 'all', to: 'trash#destroy_all', via: :delete, on: :collection
end
问题解决了 是我在垃圾箱里做的有趣的事情

    def destroy_all
        [..]
    end

    def destroy
        [..]
    end
def destroy_all
  if Slide.only_deleted.map(&destroy(force: true))
  [..]
解决方案:

偏执狂2提供毁灭一切!方法如下:

def destroy_all
  if Slide.only_deleted.destroy_all!

堆栈跟踪表明您只需从destroy_all调用destroy函数。路由与此问题无关

你说得对!问题出在我的销毁所有操作的第一行:if Slide.only_deleted.map(&destroy(force:true))有趣但典型。接受我的回答怎么样?或者你需要更多的帮助?:)例如,Slide.only_已删除。是你要找的东西。这种情况下不需要地图,我一定会的。如果你能告诉我如何解决这个问题,我将不胜感激。我的destroy def是:if@trashed\u slide.destroy(force:true)[…]其中@trashed\u slide=slide.only\u deleted.find(params[:id]),它可以正常工作,对于destroy\u,我只想对幻灯片使用destroy(force:true)。only\u删除了幻灯片。only\u deleted.destroy(force:true)给出“未知键:force”错误。请参阅我最后的评论。你只需要打电话给destroy_all进行收集。你想用武力来达到什么目的?