Reputation: 2902
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!
Upvotes: 4
Views: 1873
Reputation: 2902
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 %>
Upvotes: 6