2012-07-08 114 views
2

我使用friendly_idhistory模块一个名为page模型,并希望能够从friendly_id_slugs表中删除蛞蝓,使他们不再重定向和可再次使用删除蛞蝓。friendly_id,从历史

我想出了几个可能的解决方案,但我不能确定如何进行:

  1. 创建的friendly_id_table一个新的模型和控制器和做的事情,我会为任何其他模式
  2. 一个destroy_slug行动加入pages_controller.rb看起来了蛞蝓和毁坏它 - 但是,我不能确定如何加载蛞蝓,也许FriendlyId::Slug.find()
  3. 创建于FriendlyId命名空间的控制器 - 不知道如何做到这一点

任何人都可以提出一个建议作为继续或如何完成#2或#3的最佳方式?谢谢!

回答

5

目前我实现这个像这样:

# 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 %>