【发布时间】:2015-04-21 05:56:09
【问题描述】:
我的 rails 应用程序中有 Job 模型和 Location 模型。我使用 postgresql 作为数据库。所以我将 location_ids 作为我的 Job 模型中的一个数组字段来保存位置。我在我的应用程序中使用 FeriendlyId 来使我的 url 友好。当我进入我的工作展示页面时,我得到了这个友好的网址
http://localhost:3000/jobs/seo-trainee
但现在我还想在我的 url 中包含工作的位置,就像这样
http://localhost:3000/jobs/seo-trainee-mumbai-tokyo
我知道我们可以为此目的使用 slug_candidates。但我不知道我怎样才能做到这一点
目前我的工作模型中有这个
extend FriendlyId
friendly_id :slug_candidates, use: [:slugged, :finders]
def slug_candidates
[
:title,
[:title, :id]
]
end
【问题讨论】: