I am using friendly_id with the history module for a model called page and would like to be able to delete slugs from the friendly_id_slugs table so that they no longer redirect and can be used again.
I have come up with a couple of possible solutions, but am unsure of how to proceed:
friendly_id_table and do things as I would for any other modeldestroy_slug action to pages_controller.rb that looks up the slug and destroys it - however, I'm unsure of how to load the slug, maybe FriendlyId::Slug.find()FriendlyId namespace - no idea how to do thisCan anyone make a suggestion as the best way to proceed or how to accomplish #2 or #3? Thanks!
I currently am implementing this as like so:
# slug_controller.rb
class SlugsController < ApplicationController
def destroy
@slug = FriendlyId::Slug.find(params[:id])
@slug.destroy
redirect_to :back, :notice => "The URL <strong>/#{@slug.slug}</strong> has been removed"
end
end
# routes.rb
resources :slugs, :only => :destroy
# in a view
<%= link_to 'Delete slug', slug_path(slug.id), :method => :delete %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With