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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:40:02+00:00 2026-05-20T20:40:02+00:00

In a rails 2 app I’m building, I have a need to update a

  • 0

In a rails 2 app I’m building, I have a need to update a collection of records with specific attributes. I have a named scope to find the collection, but I have to iterate over each record to update the attributes. Instead of making one query to update several thousand records, I’ll have to make several thousand queries.

What I’ve found so far is something like Model.find_by_sql("UPDATE products ...)

This feels really junior, but I’ve googled and looked around SO and haven’t found my answer.

For clarity, what I have is:

ps = Product.last_day_of_freshness
ps.each { |p| p.update_attributes(:stale => true) }

What I want is:

Product.last_day_of_freshness.update_attributes(:stale => true)
  • 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-20T20:40:03+00:00Added an answer on May 20, 2026 at 8:40 pm

    It sounds like you are looking for ActiveRecord::Base.update_all – from the documentation:

    Updates all records with details given if they match a set of conditions supplied, limits and order can also be supplied. This method constructs a single SQL UPDATE statement and sends it straight to the database. It does not instantiate the involved models and it does not trigger Active Record callbacks or validations.

    Product.last_day_of_freshness.update_all(:stale => true)
    

    Actually, since this is rails 2.x (You didn’t specify) – the named_scope chaining may not work, you might need to pass the conditions for your named scope as the second parameter to update_all instead of chaining it onto the end of the Product scope.

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

Sidebar

Related Questions

I have a rails app (Rails 3.0) that I need to temporarily take out
I have a rails app that was working fine with sqlite but upon switching
In my ruby on rails app I have to use recursion to render nested
In my Rails app I need to get the dates for the next occurrence
I have a rails app that uses the following, rails 3.1, ruby 1.9.2, mysql,
So I have a rails app with a url field for embedding youtube and
I am creating a rails app. And i have login in such a way
I have a rails app where i have a Contact model and with an
I am building a rails app that has a number of models, one of
in my Rails app have this routes.rb: devise_for :admin namespace :admin do root :to

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.