If I understood it correctly, your problem is about sharing data between models, not about FriendlyId.
It seems delegate
is your best bet here. It's a method in ActiveSupport that allows one model to expose another model's methods as their own.
class User < ActiveRecord::Base
delegate :name, :name=, :to => :user_profile
end
Reference: http://api.rubyonrails.org/classes/Module.html#method-i-delegate
The reason to delegate both :name
and :name=
is that the former method allows you to read from that attribute (getter), while the latter allows you to write to it (setter).
Before making these changes you'll want to run a migration to remove the name
field from the users
table in the database, since from now on you'll be using the data in the other model.
rails g migration remove_name_from_users name:string