Question

I have user model and a car model

I want to have a model which will hold the settings for each car and each user

so I do

class CarSettings < ActiveRecord::Base

  belongs_to :user
  belongs_to :car
end

for user:

  has_many :car_settings

and for cars:

  has_many :car_settings
  has_many :users, :through => :car_settings

note the name CarSettings, this isn't a mistake, I want it to be settings and not setting

When I do

c=Car.first
c.users

I get

NameError: uninitialized constant Car::CarSetting
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/inheritance.rb:111:in `compute_type'

it is looking for a singular car_setting and not car_settings.

How can I fix this?

Was it helpful?

Solution

You can force the class name on the association using this option:

has_many :car_settings, :class_name => "CarSettings"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top