【问题标题】:Friendly_id User or Profile modelFriendly_id 用户或配置文件模型
【发布时间】:2017-05-15 06:51:56
【问题描述】:

我将 User(has_one :profile) 模型链接到 Profile(belongs_to :user) 模型。

我将使用用户名来 slug profile url,友好应该在 User 或 Profile 模型中实现?

谢谢!

【问题讨论】:

  • 用户或个人资料中的姓名列在哪里?

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


【解决方案1】:

我仍然会将它添加到Profile,因为您需要它来构建profile_url,而不是user_url,然后将username 委托给User

class Profile < ActiveRecord::Base
  extend FriendlyId

  belongs_to :user

  friendly_id :username, use: :slugged
  delegate :username, to: :user

  # ...
end

【讨论】:

    猜你喜欢
    • 2011-10-09
    • 2017-11-07
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多