【问题标题】:defining slug candidates from associated db with friendly_id从关联的数据库中定义 slug 候选者与friendly_id
【发布时间】:2014-06-28 14:41:06
【问题描述】:

我有一个 Application.rb

belongs_to :company

Company.rb可以

has_many :applications

我在 Company 模型上设置了friendly_id,但也希望在我的应用程序上使用它。但是应用程序不会将我想要的内容存储为 slug_candidates。我希望从应用程序所属的公司中提取 slug 候选人。

这是我的Applicatio.rb

extend FriendlyId
 friendly_id :slug_candidates, use: [:slugged, :history]

def slug_candidates
 [
  :intern_type,
  [:intern_type, Company.city]
 ]
end

我将如何设置它以便它应该从公司获取它?

【问题讨论】:

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


    【解决方案1】:

    我认为你应该可以在Application模型中做,

    def slug_candidates
      [
        :intern_type,
        [:intern_type, company.city]
      ]
    end
    

    我认为这个stack overflow question 有类似的问题。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2014-03-30
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 2018-10-12
      • 2015-02-12
      相关资源
      最近更新 更多