activerecord - Enforcing a has_one association -


i using devise user model related legacy table , fine works perfectly.

now want implement ability reset passwords, , enforces having new fields (reset_password_token , reset_password_token_at), cannot create on original table.

i decided use old delegate has_one relationship. here's did:

class user < legacydatabase   set_table_name 't_clients'    devise :database_authenticatable, :authentication_keys => [:email]   devise :recoverable    has_one :user_setting    delegate :reset_password_token,   :to => :user_setting   delegate :reset_password_sent_at, :to => :user_setting    # (...) end 

my problem need enforce users have usersetting created when need access new fields.

if doing hand, usersetting.find_or_create_by_user_id(...), before going down path, i'd know if rails provides way accomplish without falling manual code.

ok, how ugly approach (seems work):

alias :old_user_setting :user_setting  def user_setting   old_user_setting || create_user_setting end 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -