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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:21:31+00:00 2026-05-31T07:21:31+00:00

Suppose I have the following method. def create_multiple project = Project.find(params[:project]) params[:tasks].each_value { |task|

  • 0

Suppose I have the following method.

def create_multiple
  project = Project.find(params[:project])
  params[:tasks].each_value { |task| @tasks << @project.tasks.build(task) }
  project.save

  respond_with @tasks
end

I thought about changing it to call .create instead of build to create the tasks because I want them to save if there are no validation errors, even of other tasks fail because of validation. I’m curious what others think about this idea? I thought about using create_or_update as well, but I’m thinking I want to encourage people to remove items that were successfully created rather than just repeatedly calling with the same list until all items are created.

Is there a better way to do this so I can continue to call .save once and have it create ones that pass validation and fails the ones that don’t without failing out entirely?

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

    Not sure exactly what you’re trying to achieve, but if you want to avoid calling save on those which fail validation how about just making new tasks, filtering for valid, and attaching them to the project after that?

    def create_multiple
      project = Project.find(params[:project])
    
      @tasks = params[:tasks].map{ |task| Task.new(task) }
                             .select{ |task| task.valid? }
      project.tasks = @tasks 
      project.save
    
      respond_with @tasks
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have following code defined in tester.py class Tester( object ): def method(
I have the following method that is supposed to be a generic Save to
Suppose I have the following directory layout in a Maven project: src/ |-- main
Suppose I have the following object: class Foo(object): def __init__(self, name=None): self.name = name
Suppose we have the following method (it is in c code): const char *bitap_search(const
Suppose I have the following piece of code public synchronized void method() { if(something
Suppose I have a method that combines several address fields like so: def address
Suppose that I have the following python base class: class BaseClass(object): def a(): This
Suppose I have the following java method protected void onEvent(Object obj) { } The
Suppose I have a method def f(s:String *) = s.foreach( x => println(x) )

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.