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 6568489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:29:04+00:00 2026-05-25T14:29:04+00:00

I have a User.rb model and a UserSetting.rb model that i would like to

  • 0

I have a User.rb model and a UserSetting.rb model that i would like to delegate to (both getter and setter methods).

in user.rb

delegate :email_opt_in, :email_opt_in=, :to => :user_setting

At first glance this works great.

user = User.find(1)
user.email_opt_in #=> false
user.email_opt_in = true
user.save
user.email_opt_in #=> true

But looking closer the, user.save doesn’t propagate to the UserSetting model.

User.find(1).email_opt_in #=> false

(So the value didn’t get saved to the database).

This is my question: How can I get UserSetting to save automatically when one of its attributes are changed and then saved by its user?

This should only happen when a UserSetting attribute is changed otherwise every time a user is saved to the database it will trigger an additional un-needed & unwanted write to the database.

  • 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-25T14:29:05+00:00Added an answer on May 25, 2026 at 2:29 pm

    I would explore using an ActiveRecord callback for this. I’m not sure which would make the most sense in your case, but before_update or after_update seem logical. In your callback, you would need to manually trigger a save call on the UserSetting object associated with the User. There’s probably dozens of ways to accomplish this, but something along these lines should work:

    class User < ActiveRecord::Base
      after_update do |user|
        user.user_setting.save if user.user_setting.changed?
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a User model that :has_many other models like Documents, Videos, Posts
I have a User model in my app, which I would like to store
I have a user model that has properties such as username, password, first name,
I have a user model on which I check to make sure that the
I have a user model that requires the user to change their password every
For instance, let's say I have a User model. Users have things like logins,
I have a User model that has many fights. Fight belongs to User. There
I have a User model that has_many :posts. If I wanted to make a
I'm new to MVC. You have been warned... I have User model that can
I have a User model that contains information such as username, email, hometown, etc.

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.