我正在运行Rails 3.2.13和Ruby 2.1.0。
此错误以看似随机的方式出现。我的应用中只有一个Location类。但我最近添加了几款新宝石:Rmagick,CarrierWave和CarrierWave-Azure。
这是错误:
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'
如果我去company_controller.rb ln 24,则会出现以下代码:
@addresses = @company.addresses
第23行:实际上是引用位置:
@locations = @company.locations
如果我在调试模式中单步执行代码,则在第23行执行时不再创建@locations变量,将创建第23行之前的所有其他变量。我几个月没有触及这个代码,最近唯一添加到代码库的内容围绕我上面列出的宝石,但没有包括对Location.rb,Company.rb,Address.rb或Companies_Controller的更改。
任何人都知道这里发生了什么? THX!
更新: 这是我的位置模型:
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
答案 0 :(得分:0)
您的 gems/plugins
之一已经定义了 Location Class
.So就是错误。
要解决此问题,您应该将应用中的 Location
类更改为 Location1
class Location1 < ActiveRecord::Base
这可以解决您的问题。并且不要忘记将 Model
文件名更改为 location1.rb