How to make link_to recover soft deleted Items?

409 Views Asked by At

I'm using Rails 4.2 an also using ActsAsParanoid gem to soft delete items from database.

I've created a controller action to index .only_deleted objects...

sample_controller.rb

  class FlavorsController < ApplicationController
    ...
    def inactive
      @flavors = Flavor.only_deleted
      render action: :index
    end
    ...
   end

I'm using a partial _flavor to render Flavor's, And I wonder how to make link_to view helpers to restore this object? Something like...

  <%= link_to "Recover", flavor.recover %> 
1

There are 1 best solutions below

0
Moataz Zaitoun On BEST ANSWER

Thanks to fanta's comment, I could find the answer...

1st add member to my routes

  resources :flavors
    collection do
      get 'inactive'
    end
    member do
      get 'recover'
    end
  end

Then in my inactive_index.html.erb I added the link below

  <%= link_to recover_flavor_path(flavor) %>