超类必须是一个类(模块给定)(TypeError)错误Rails 4 Ruby 2.1.2

时间:2014-08-14 22:36:20

标签: ruby-on-rails ruby

只是尝试在我的rails应用程序中运行迁移(rails 4,ruby 2.1.2)并继续收到此错误:

superclass must be a Class (Module given) (TypeError)

这是堆栈:

rails g migration createCompany
/home/javier/Drivers/app/models/driver.rb:1:in `<top (required)>': superclass must be a Class (Module given) (TypeError)
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:443:in `load'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:443:in `block in load_file'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:633:in `new_constants_in'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:442:in `load_file'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:342:in `require_or_load'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:480:in `load_missing_constant'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:180:in `const_missing'
    from /home/javier/Drivers/app/admin/driver.rb:1:in `<top (required)>'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
    from /home/javier/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-b8e89c747881/lib/active_admin/application.rb:179:in `block in load'
    from /home/javier/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-b8e89c747881/lib/active_admin/error.rb:23:in `capture'
    from /home/javier/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-b8e89c747881/lib/active_admin/application.rb:179:in `load'
    from /home/javier/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-b8e89c747881/lib/active_admin/application.rb:171:in `block in load!'
    from /home/javier/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-b8e89c747881/lib/active_admin/application.rb:171:in `each'
    from /home/javier/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-b8e89c747881/lib/active_admin/application.rb:171:in `load!'
    from /home/javier/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-b8e89c747881/lib/active_admin/application.rb:193:in `routes'
    from /home/javier/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-b8e89c747881/lib/active_admin.rb:80:in `routes'
    from /home/javier/Drivers/config/routes.rb:8:in `block in <top (required)>'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:315:in `draw'
    from /home/javier/Drivers/config/routes.rb:1:in `<top (required)>'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `each'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/file_update_checker.rb:75:in `call'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/file_update_checker.rb:75:in `execute'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/javier/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /home/javier/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /home/javier/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /home/javier/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /home/javier/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /home/javier/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /home/javier/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /home/javier/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /home/javier/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
    from /home/javier/Drivers/config/environment.rb:5:in `<top (required)>'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application.rb:276:in `require_environment!'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:147:in `require_application_and_environment!'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:133:in `generate_or_destroy'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:51:in `generate'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

驱动程序类:

class Driver < Instructor 
    has_one :status
  has_many :driver_products
  has_many :driver_services
  has_many :services, :through => :driver_services
    belongs_to :town
  belongs_to :county 
  belongs_to :country

  geocoded_by :full_address
  after_validation :geocode, :on => :update


  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable

  def full_address
   "#{self.address_line_1}" + "," + "#{self.address_line_2}" 
  end

  def full_name
   "#{first_name}" + " " + "#{second_name}"
  end 
end

更新了宝石并尝试运行:

rails g devise讲师,但不断收到相同的错误。

*注意:我已经删除了表教练

任何想法? 干杯 Ĵ

1 个答案:

答案 0 :(得分:1)

当我的迁移代码是这样的:

class AddSalePriceToSpreeVariants < SpreeExtension::Migration
  def change
    add_column :spree_variants, :sale_price, :decimal, precision: 8, scale: 2
  end
end

我遇到了同样的错误, 然后我在代码的第一行添加了 rails version [6.0],如下所示:-

class AddSalePriceToSpreeVariants < SpreeExtension::Migration[6.0]
  def change
    add_column :spree_variants, :sale_price, :decimal, precision: 8, scale: 2
  end
end

错误已解决...