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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:11:42+00:00 2026-06-18T04:11:42+00:00

In my create action on a form, I successfully save (1) MyObject to my

  • 0

In my “create” action on a form, I successfully save (1) MyObject to my local database and (2) OtherObject to a third-party database via its Ruby API. When something goes wrong with the save to the third party, I get an error in the form of a Ruby exception.

My question is: How do I stop the form submit and report the exception message to the client?

If this is not possible, what would be the best alternative?

  • 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-18T04:11:44+00:00Added an answer on June 18, 2026 at 4:11 am

    Depending on whether you want to rollback your local database call, you might want to consider using Transactions. Something along these lines:

    def create
      ActiveRecord::Base.transaction do
        @myobject = MyObject.create!(params[:myobject])
        begin
          # call third-party
        rescue Exception => e
          flash[:exception] = e.message
          raise ActiveRecord::Rollback # Raise this to cause a rollback on MyObject
        end
      end
      # redirect_to or render... might have to pick depending on if you got an exception
    end
    

    This will store the exception message into the flash which you can use to display to the user. Note Do not store the entire Exception object into the flash, you will definitely see overflow errors if your exception objects are too big.

    If you’re not too concerned about rolling back the MyObject creation, then you can just use a simple begin…rescue similar to what I showed in my example. You may need to determine whether you want to do a redirect_to or render depending on whether an exception occurred, but you can always conditionally determine that based on whether flash[:exception].nil? is true or not.

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

Sidebar

Related Questions

I have a create action for a form that potentially generates errors (i.e. first
I have a create action in the controller that I use for a form
I've create a form like: function create_custom_form($form, &$form_state) { $form['#action'] = #; .... }
I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have done the following form <% form_for @anexo, :url => {:action => create},
I have a form that save a question and five answers in the database
I have a form successfully submitting data via ajax, but I can't figure out
I created a login page using spring_security_check. Here: <form name='f' action=/sec_test/j_spring_security_check method='POST'> <table> <tr>
I am trying to create an admin instance through my admins controller create action,
I need to upload an image as part of a create action in an

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.