user#role
モジュールで関連付けを定義するために参照する必要があります。以下に示すようにブロックで試しましたが、うまくいきません。Rails はこのような動作をどのように実装しますか?
class User < ActiveRecord::Base
include Profile
has_profile { |user| { class_name: "#{user.role}::Profile" }}
end
module Profile
extend ActiveSupport::Concern
module ClassMethods
def has_profile(&block)
role = ### How to access #role ? ###
class_eval do
has_one :profile, class_name: "#{role}::Profile"
end
...