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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:23:15+00:00 2026-05-24T03:23:15+00:00

I have lets say 5 models. Thread Poll Message Wall Zone I would like

  • 0

I have lets say 5 models.

Thread
Poll
Message
Wall
Zone

I would like something where I can loop through each model contained in the string or array, and if that model has a user_id field, update it to whatever I’d like to set it to.

Any Idea on how you can do something like

[Thread.where(:user_id => XXX)].each do |model|
 ...
end

Where Thread is looped through in a list of models [“Thread”, “Poll”, ….]

Thanks

  • 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-24T03:23:16+00:00Added an answer on May 24, 2026 at 3:23 am

    try this:

    models = ["Thread", "Poll", ....]
    
    models.each do |model|
      model = model.constantize
      if model.columns.map(&:name).include?("user_id")
        model.where(:user_id => my_user_id).each do |m|
          do_stuff_with(m)
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have the following class structure in my data access layer: interface
Lets say that I have a table containing users . Each row in that
Lets say, I have the following text file: Listing 1: Endianess=little AddressModel=32 typedef struct{
If I have two threads in my Cocoa app, and (let's say), I'm reading
So I have a custom ViewModel ( CompanySalaryDataViewModel ) that has a collection of
I am still a bit confused about the relation of Proxy models to their
Note: This is a long winded question and requires a good understanding of the
Background: We're modeling the firmware for a new embedded system. Currently the firmware is
I'm trying to build a multi model form - but one of the issues,
Okay, so here's an example scenario. There is a student resource resources :students ,

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.