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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:59:55+00:00 2026-06-03T02:59:55+00:00

In my model I have custom validation method that sends request to the external

  • 0

In my model I have custom validation method that sends request to the external service. Based on the response I add errors to errors array if any.

If there are errors, I also need to create new records of ErrorLog models, which represents error log. The problem is that when validation fails, it performs ROLLBACK on database, and all my new ErrorLog records are lost. What is the best way to implement it?

I also should say that after_rollback is not called for some reason.

  • 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-03T02:59:55+00:00Added an answer on June 3, 2026 at 2:59 am

    after_rollback is only called on objects that are saved or destroyed during the transaction. Are you setting up the after_rollback callback on your main class or on your ErrorLog class?

    In fact, using the after_rollback callback on your ErrorLog class would seem to be the easiest approach. The only case where you’re going to lose the ErrorLog instances is if the transaction is rolled back so something like this should work:

    class MyClass < ActiveRecord::Base
      before_save :check_external
    
      def check_external
        unless external_says_i_am_okay?
          ErrorLog.create!(:message => 'oops')
        end
      end
    end
    
    class ErrorLog < ActiveRecord::Base
      after_rollback :save_anyway
    
      def save_anyway
        self.save!
      end
    end
    

    Of course having said all that you might want to consider the performance of getting an external service to validate your models. It might not be sufficiently quick if you’re creating objects in the scope of a web request for example. You’d also want to make sure that the ErrorLog#save wouldn’t fail as you’re going to be outside the scope of a transaction by that point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic entity model which I'm trying to add custom validation
I have a model class that uses a custom validator as shown in following
In my application I have a custom model binder that I set to the
I am newbie at Django. I have model with a custom method. In view
I have a Model that contains a List of a custom type. I want
I have a model that implement IValidatlableObject, and so custom error checking through Validate
I have a WCF service that I secure with a custom UserNamePasswordValidator and Message
I'm trying to write a custom validation method in my app - I have
I have a model Whitelabel and a User has_many :whitelables I have a custom
This is my custom model binder. I have my breakpoint set at BindModel but

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.