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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:02:33+00:00 2026-05-27T19:02:33+00:00

I’ve added the following to my controller’s create action: def create BatchUser.mass_insert_v2(params[:batch_user][:batch_name], params[:batch_user] [:batch_description],

  • 0

I’ve added the following to my controller’s create action:

 def create 
   BatchUser.mass_insert_v2(params[:batch_user][:batch_name], params[:batch_user]  [:batch_description], params[:batch_user][:quantity])
  redirect_to batch_users_path
 end

‘mass_insert_v2’, in my BatchUser model, starts like this:

 def self.mass_insert_v2(batch_name, batch_description, quantity)
  @batch_create = BatchUser.create! :batch_name => batch_name, :batch_description => batch_description
   ...
 end

And then goes on to create X user accounts with random usernames and passwords. I’ve chosen this route because I found raw sql insertion to be faster than using activerecord on its own.

The problem I have is that I’m struggling to render my error messages. For example, batch_name must be present and unique.

I do get an error screen:

 ActiveRecord::RecordInvalid in BatchUsersController#create

But no errors show.

Previously, I’ve had this check in my controller:

 respond_to do |format|
   if @batch_user.save
   ....
   else
   ....

But that doesn’t seem to work anymore. What can I do to display the errors on the page??

  • 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-27T19:02:33+00:00Added an answer on May 27, 2026 at 7:02 pm

    The create! (create with bang!) will throw an exception if the object fails validations. Unless you are planning on catching this exception and handling you might be better off just using create and then checking if the object was created successfully (has an id) and/or has errors.

    There are several railsy ways of handling the finding and rendering error messages so you can experiment. However, knowing the following along with the important note above will help get you on track I think:

     @batch_user = BatchUser.create(attr_hash) #will give you an object to work with instead of throwing an exception.
    

    If you have an existing object:

     @batch_user.valid? #will trigger the validations only and set the object's errors attribute with any relevant data and return a boolean value.
    
     @batch_user.errors #gives you access to the error data (in 3.1 ActiveModel::Errors object)
    

    As far as actually rendering the errors, like I said there are several options. I prefer either putting those error messages (obj.errors.full_messages) in the flash or using something like the dynamic_form plugin.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, 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.