Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6092657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:28:07+00:00 2026-05-23T12:28:07+00:00

I am using devise but the User model is related to a legacy table

  • 0

I am using devise but the User model is related to a legacy table and so fine it works perfectly.

Now I want to implement the ability to reset passwords, and that enforces having new fields (reset_password_token and reset_password_token_at), which I cannot create on the original table.

I decided to use the good old delegate with a has_one relationship. Here’s what I 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 now is that I need to enforce that all users will have a UserSetting created when I need to access the new fields.

If I was doing it by hand, I could do the UserSetting.find_or_create_by_user_id(…), but before going down that path, I’d like to know if rails provides a way to accomplish this without falling back to manual code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:28:07+00:00Added an answer on May 23, 2026 at 12:28 pm

    OK, how ugly is this approach (seems to work):

    alias :old_user_setting :user_setting
    
    def user_setting
      old_user_setting || create_user_setting
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

rails 3 newbie, using Devise for auth... I want to create the following models:
I'm using Devise and have models set up like this: User has_one :profile Profile
I want to override Devise's RegistrationsContollers ' create action so that when a user
I have a User model that Devise manages - i.e. all users have email
Using MVC with an observer pattern, if a user action requires polling a device
What I want : To know when the user has pressed the button that
I'm using Devise as authenticating solution in Rails and I have a cached fragment
I'm trying to get some basic authentication/authorization with devise/cancan with Rails. Rather than using
On my development machine I can login fine, but once on production, authentication fails
A number of Rails 2.3 apps are using Restful Authentication but that plugin seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.