Pregunta

The problem is solved and wasn't on the Rails router which I blamed. I hope leave this helpfull to someone who wants to implement Trash functionality with paranoid2 gem.

I'm using paranoid2 gem (like acts-as-paranoid but for Rails4) to protect my data from beeing accidently deleted which works fine and I'm trying to create Trash to my app. It should show what's marked as deleted (done), give a way to restore the data (todo), permanently delete (done) and empty whole Trash (this is the problem).

Those my routes which works fine:

trash_index GET    /trash(.:format)                       trash#index
      trash GET    /trash/:id(.:format)                   trash#show
            DELETE /trash/:id(.:format)                   trash#destroy

and the one more I have but it doesn't work as I want:

all_trash_index DELETE /trash/all(.:format)                   trash#destroy_all

Looks fine for me as it uses DELETE, doesn't require :id parameter and should route to trash#destroy_all which I have in my trash_controller.rb:

    def destroy_all
        [..]
    end

    def destroy
        [..]
    end

But when I try to get there I end up with error:

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'

why I end up in 'destroy' action? ..and got errors for both destroy and destroy_all

This is my routes.rb:

resources :trash, only: [:index, :show, :destroy] do
    match 'all', to: 'trash#destroy_all', via: :delete, on: :collection
end

THE PROBLEM IS SOLVED

was by funny thing I did in trash_controller.rb:

def destroy_all
  if Slide.only_deleted.map(&destroy(force: true))
  [..]

solution:

paranoid2 provides destroy_all! method so:

def destroy_all
  if Slide.only_deleted.destroy_all!
¿Fue útil?

Solución

Stack trace indicates you just call destroy function from destroy_all. Routing have nothing to do with this problem.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top