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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:18:43+00:00 2026-06-08T06:18:43+00:00

I have an Rails 3.2 app, and I have one model, let’s call it

  • 0

I have an Rails 3.2 app, and I have one model, let’s call it Car.

The user inputs a series of information, and the app returns a list of suggested cars based on that information. Now, each car has a set of transient properties that a user may or may not want, such as suggested upholstery, suggested color, etc. These “suggested” properties are calculated on the fly based on the information the user enters. So not only does the app guess what cars the user might want, it also guesses what additional options the user might want, and stores that information transiently on the Car record.

This is a pseudocodish representation of the relevant part of the Car model:

def self.suggested_cars
  @cars = basic_cars(user_height, user_weight)
  add_upholstery_suggestions(@cars, user_wealth)
  add_color_suggestions(@cars, user_gender)
end

The issue is that the algorithms for suggesting cars and options can return actual Car records that are not distinct. For example, one request for suggested cars can return Both Car A and Car A with leather seats. But then I have an issue, because when requesting two of the same entity from active record at the same time, both instances refer to the same object, i.e. they can’t have different transient data.

I suspect that I might need to use the .dup method to copy objects when that happens, but I feel like there is a more elegant solution. I’m open to any suggestions. Is there a common way to handle this type of situation?

  • 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-06-08T06:18:44+00:00Added an answer on June 8, 2026 at 6:18 am

    The problem is that you have two different things that you’re trying to force into one. One is a list of car types; the other is a list of car configurations. A car configuration has one car type. A car type has many configurations.

    Fix by turning them into two different classes, e.g.:

    class Car < ActiveRecord::Base
      def self.basic_cars(user)
        # returns a relation
      end
    end
    
    class CarConfig
      attr_accessor :car, :opts
    
      def initialize(car, opts)
        @car, @opts = car, opts
      end
    
      def self.suggested_configs
        configs = []
        Car.basic_cars(user).each do |car|
          configs << upholstery_suggestions(car, user)
          configs << color_suggestions(car, user)
        end
        configs.flatten
      end
    
      def self.upholstery_suggestions(car, user)
        [self.new(car, seats: 'standard'), 
         self.new(car, seats: 'leather')]
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Rails app, I have a model Page which represents one HTML article
I have a little one-liner in my Rails app that returns a range of
I've a mongoid embedded one to one model in a Rails app (User -->
I have a naked rails 3 app with one model, generated using rails g
In my Rails 3 app, I have a model called User with id and
In my current rails app, I have a User model which has_one :user_detail. Currently,
I have a rails 3.2 app that uses 2 databases. One database is the
I am creating a rails app and have used this code in one of
I have a Rails app with the usual application_controller, and a controller (and model)
I have a rails app where i have a Contact model and with an

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.