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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:33:14+00:00 2026-05-21T02:33:14+00:00

I am updating the attributes of two models from one form. User.transaction do begin

  • 0

I am updating the attributes of two models from one form.

User.transaction do
          begin
             @user.update_attributes!(params[:user]) 
             @board.update_attributes!(params[:board])
          rescue ActiveRecord::RecordInvalid
        end
      end

When the @user.update_attributes produces an error the transaction is stopped and the error message is shown in the view.

However I want to try to update both @user and @board and get the error messages for both so that the user can correct all their mistakes one time.

How can I do this?

Thank you very much in advance.

  • 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-21T02:33:15+00:00Added an answer on May 21, 2026 at 2:33 am

    You could do the following:

    User.transaction do
      @user.update_attributes(params[:user])
      @board.update_attributes(params[:board])
      raise ActiveRecord::Rollback unless @user.valid? && @board.valid?
    end
    

    This will ensure that both update attribute methods run so that you can get error messages for both objects. If either object is invalid though no changes will be persisted to the database.

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

Sidebar

Related Questions

I'm updating one of my models and I'm sending in a dictionary of attributes
Hi I want to use two params hashes in one page The job of
I have two models, Page and PageContent. class Page < ActiveRecord::Base has_many :page_contents end
Let's say I have two ActiveRecord models: LineItem and Article. class LineItem < ActiveRecord::Base
After updating to php 5.3 one of our systems has developed an interesting bug.
After updating to Parsec 3.1 from 2.x, code using many1, such as word =
I have two images next to each other in HTML. One image is taller
I am looking up all Organizations with the url http://, and updating their attributes
I have a registration form for registering personal attributes. I am using both included
In my app, I have a User model, which includes a number of attributes

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.