缓存Friendly_id插件

发布于 2024-08-03 10:06:07 字数 176 浏览 7 评论 0原文

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

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

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

What is the most efficient method to store the slugs within the 'products' table.
I have complex find queries, and the joins with the 'slugs' table give me performance bottlenecks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梨涡少年 2024-08-10 10:06:07

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

问题中的代码片段来自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,包括历史记录(避免 404s) 等...

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

Ok, I know this is an old question, but just wanted to note, for others that may stumble across this:

The code snippet in the question is from FriendlyId 3.x in which case you would add a column to your table (call it anything except for slug ... I prefer to use cached_slug) as a string and update the model to show

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

As of friendly_id 4.x, you simply just add a slug column as a string to the table, and use the new syntax:

eg:

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

There are a whole bunch of options and ways to get the most out of friendly_id including historical records (to avoid 404s) etc ...

More information: http://rubydoc.info/github/norman/friendly_id/master/frames

春夜浅 2024-08-10 10:06:07

Friendly_id 现在有内置的 slug 缓存。

Friendly_id now has built-in slug caching.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文