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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:18:07+00:00 2026-06-08T13:18:07+00:00

I have an enrollment form. When the user enrolls, the app is supposed to

  • 0

I have an enrollment form.

When the user enrolls, the app is supposed to save the data in the enrollments table and in the users table. (I need this separation because the user’s profile can change but the data he entered for that particular enrollment has to be archived. So even if later the user changes his last name, in the enrollment form I’ll have his initial information.)

So I was thinking about saving data in the enrollments table then have a after_create call, like this…

class Enrollment < ActiveRecord::Base

  after_create :save_corresponding_user

  def save_corresponding_user
    user = User.new
    user.full_name = self.user_full_name
    user.email = self.user_email
    user.mobile_phone = self.user_mobile_phone
    user.save
  end
end

The issue is, what if saving the user fails for any reason. How can I rollback and destroy the just saved data from the enrollments table?

  • 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-08T13:18:10+00:00Added an answer on June 8, 2026 at 1:18 pm

    after_create is a part of the transaction saving the current model. Therefore, if your code crashes or if after_create returns false, it should rollback the current transaction and invalidate the enrollment saving.

    If you want to simulate this, add this to your after_create and see if everything works as expected :

    raise Exception.new("CRASH")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a table called enrollments and this is my current basic enrollment
I have a enrollment form where users have to input there address. I am
Problem Overview: My application has an enrollment form. Users have a habit of entering
I have a form page where users enter some data and upon hitting 'submit'
I have an online form which collects consumer data and stores in a dedicated
This is a use case in member enrollment via web application/web service. We have
I have a fairly large CRUD WinForm app that has numerous objects. Person, Enrollment,
So i have a temporary table that I need to populate with the records
I've got a student table and an enrollment table; a student could have multiple
I have a model Enrollment which validates the uniqueness for each course by user:

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.