I'm running Rails 3.2.13 and Ruby 2.1.0.
This error has popped up in a seemingly random fashion. I only have one Location class in my app. But I did add several new gems recently: Rmagick, CarrierWave and CarrierWave-Azure.
Here's the error:
TypeError in CompaniesController#show
superclass mismatch for class Location
app/models/location.rb:1:in `<top (required)>'
app/controllers/companies_controller.rb:24:in `show'
If I go to companies_controller.rb ln 24 there is this code:
@addresses = @company.addresses
Line 23: actually references Location:
@locations = @company.locations
If I step through the code in debug mode the @locations variable isn't created anymore when line 23 executes, all other variables prior to line 23 are created. I haven't touched this code in months, the only recent additions to the codebase have revolved around the gems I listed above but did not include changes to Location.rb, Company.rb, Address.rb or Companies_Controller.
Anyone know what's going on here? thx!
Update: Here is my Location model:
class Location < ActiveRecord::Base
attr_accessible :address_attributes, :address, :created_by, :is_active, :location_name, :location_type_id,
:region_id, :updated_by, :website
# set schema name and table name for TakebackDBMS
self.table_name ="recycle.Location"
# define associations
has_many :companyContacts
belongs_to :location_type
belongs_to :company
belongs_to :address
belongs_to :region
default_scope order: 'location_name' # return locations list in Alphabetical order
accepts_nested_attributes_for :address, :reject_if => :all_blank
#validations
validates :location_name, presence: true, length: { maximum: 100 }
validates :created_by, length: { maximum: 50 }
end
Looks like one of your gems/plugins
already defines a Location Class
.So is the error.
To resolve this,you should be changing your Location
class in your app to some name like Location1
class Location1 < ActiveRecord::Base
This should solve your problem.And don't forget to change your Model
file name to location1.rb