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

  • SEARCH
  • Home
  • 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 8550155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:53:13+00:00 2026-06-11T13:53:13+00:00

Currenntly, my application is designed using Devise for authentication. I have it so when

  • 0

Currenntly, my application is designed using Devise for authentication. I have it so when the first user signs up, an account is created in an Accounts table and the account_id is passed to the User table. I also have it set so that each time a new account is created that user is tagged as an admin. Finally, I have it working where the admin can create new users.

My problem is that at the time the new users are created I need to have these users be assigned the same account_id as the admin to tie the users together. I can do this if I add an account_id field on the form and have the admin manually enter it. What I want to have is that this is automated in the background.

I tried many varieties without success. This is one of the unsuccesful attempts where I put the following in the user.rb

before_save :add_account_id_from_parent     

   def add_account_id_from_parent       
    return true unless self.users.present?       
    self.users.update_attribute(:account_id, 1)    
   end

I used the number “1” just to see if I could get anything automated and placed in that field.

Like I said manually everything works, but I want it so the acocunt_id is automatically added during sign up based on the admins account_id.

  • 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-06-11T13:53:15+00:00Added an answer on June 11, 2026 at 1:53 pm

    I’m a bit confused why you are calling self.users. If I understand correctly, you want to assign account_id to 1 after a new user is created (as a test). You can do that like this:

    before_save :add_account_id_from_parent
    
    def add_account_id_from_parent
      self.account_id = 1
    end
    

    You don’t need to actually update the record since this is assigned before save, and save will write the new value to the db.

    Again I might be missing something, if so please clarify.

    UPDATE:

    If you’re validating that account is present, you’ll need to change the callback to a before_validation instead of before_save, like so:

    before_validation :add_account_id_from_parent
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have designed a database for an application which contains user settings. This database
I have an application that allows, using an abstract class, people to write their
I am currently developing a Rails application using a database that was designed before
I currently have a silverlight app designed mainly in expression blend, using a border
I have a Java application that is designed to run on removable devices. One
I am using currently Xcode 4.3.2. I have developed a tiny application and specified
I have an application (currently written in Python as we iron out the specifics
I want to build a ring topology using android emulators. Currently my application has
So I'm writing an application in C# using SQLITE that will keep track of
I'm using TextMate 1.5.10 (Mac OSX 10.7.2) to write a perl modulino application .

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.