【发布时间】: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
我将 User(has_one :profile) 模型链接到 Profile(belongs_to :user) 模型。
我将使用用户名来 slug profile url,友好应该在 User 或 Profile 模型中实现?
谢谢!
【问题讨论】:
标签: ruby-on-rails ruby friendly-id
我仍然会将它添加到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
【讨论】: