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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:11:32+00:00 2026-05-20T11:11:32+00:00

My setup: Rails 2.3.10, Ruby 1.8.7 I need to update multiple instances of a

  • 0

My setup: Rails 2.3.10, Ruby 1.8.7

I need to update multiple instances of a model for a transaction. Should I make a class method and updates all the instances in the method or should I move that logic to the controller and updates each instance via an instance method for the model? I guess it is a tradeoff between fat controller vs. fat model and the general advice is fat model over fat controller.

  • 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-20T11:11:33+00:00Added an answer on May 20, 2026 at 11:11 am

    Neither. If it’s a significant piece of logic, why not incorporate it into a dedicated class?

    Alternatively, if your (I’m assuming) form data can be configured thus:

    params[:models] = { id_of_instance_1 => { :attribute => value }, 
                        id_of_instance_2 => { :attribute => value2 },
                      }
    

    You can quite easily do a group update in your controller with:

    Model.update(params[:models].keys, params[:models].values)
    

    More information about the details you’re updating and where they’re coming from could help.


    EDIT: After reading your response below…

    There’s a few ways you could do it. You could implement Model.win and Model.lose as class methods to incorporate the logic, then simply call those methods from your controller:

    def process_outcome
      @winner = Model.win(params[:winning_id])
      @loser = Model.lose(params[:losing_id])
    end
    

    Or, even as a single method call:

    def process_outcome
      # passing the entire params hash to `process_outcome` which returns an array
      @winner, @loser = Model.process_outcome(params)
    end
    

    Personally, if the only child objects involved are all instances of the same model, I’d implement this logic within the class itself.

    However, if you’re bringing a variety of classes into the mix, it might be worth encapsulating it into a separate object altogether:

    # app/controllers/models_controller.rb
    def process_outcome
      @outcome_processor = OutcomeProcessor.new(params)
      @winner = @outcome_processor.winner
      @loser  = @outcome_processor.loser
    end
    

    Either way, your actual transaction block should not be in the Controller.

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

Sidebar

Related Questions

My setup: Rails 3.0.9, Ruby 1.9.2 Here are my models class Project has_many :tasks
I'm trying to get Ruby on Rails setup on my new eeeubuntu install and
I've been trying to get setup with Ruby on Rails today, but I think
everyone. I used Ruby and Rails before, and I enjoy Rails's ORM, which make
I need to get Ruby on Rails (3.0.9) installed onto a production server that
My setup: Rails 2.3.10, Ruby 1.8.7 I'm using the will_paginate plugin and for a
My setup: Rails 2.3.10, Ruby 1.8.7 I would like some feedback on where it
My setup: Rails 3.0.9, Ruby 1.9.2 I added a custom action to a nested
My setup: Rails 3.0.9, Ruby 1.9.2 Due to a bug in Rack 1.2.3, I'm
What do I need to do to get traffic to my ruby on rails

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.