【问题标题】:Caching friendly_id plugin缓存friendly_id插件
【发布时间】:2009-08-28 15:10:41
【问题描述】:
Class Product < ActiveRecord::Base
  has_friendly_id :name, :use_slug => true
end

在“产品”表中存储 slug 的最有效方法是什么。 我有复杂的查找查询,与“slugs”表的连接给我带来了性能瓶颈。

【问题讨论】:

    标签: ruby-on-rails seo friendly-id


    【解决方案1】:

    好的,我知道这是一个老问题,但只是想指出,对于可能偶然发现此问题的其他人:

    问题中的代码 sn-p 来自 FriendlyId 3.x,在这种情况下,您可以在表中添加一列(除了 slug 之外的任何名称......我更喜欢使用 cached_slug)作为字符串并更新模型以显示

    Class Product < ActiveRecord::Base
      has_friendly_id :name, :use_slug => true, :cache_column => 'cached_slug'
    end
    

    从friendly_id 4.x 开始,您只需将slug 列作为string 添加到表中,并使用新语法:

    例如:

    Class Product < ActiveRecord::Base
      extend FriendlyId
      friendly_id :name, :use => :slugged
    end
    

    有很多选项和方法可以充分利用friendly_id,包括历史记录(以避免404)等......

    更多信息:http://rubydoc.info/github/norman/friendly_id/master/frames

    【讨论】:

      【解决方案2】:

      Friendly_id 现在有内置的 slug 缓存。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-15
        • 2015-04-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多