0

I have User(has_one :profile) model linked to a Profile(belongs_to :user) model.

I will use username to slug profile url, the friendly shoud be implemented in User or Profile model?

Thank you!

Adolfo
  • 131
  • 1
  • 3
  • 10

1 Answers1

0

I would still add it to Profile, because you need it to build a profile_url, not an user_url, but then delegate username to User:

class Profile < ActiveRecord::Base
  extend FriendlyId

  belongs_to :user

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

  # ...
end
spickermann
  • 100,941
  • 9
  • 101
  • 131