0

这是一个错误,但我调用了一些模型Test(因为它实际上是一个测试)。现在回滚它并给模型另一个名字真的很晚,因为这样我需要检查很多关于更改模型名称的代码。问题。当我在控制台中调用有关 Test 的任何内容时,它会导致错误。

>> User.last
  #<User id: 44, email: nil, password_digest: nil, created_at: "2013-05-08 11:26:04", updated_at: "2013-05-08 11:26:04", guest: true>

User Load (4.0ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1

>> @test=Test.last
NoMethodError: undefined method `last' for Test:Module
    from (irb):7
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
    from C:/Users/HP/study/script/rails:6:in `require'
    from C:/Users/HP/study/script/rails:6:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

我能做些什么?

4

1 回答 1

1

您可以重命名模型,rails g migration rename_test. 然后像这样编辑迁移

class RenameTest < ActiveRecord::Migration
  def self.up
    rename_table :test, :my_test
  end

 def self.down
    rename_table :my_test, :test
 end
end
于 2013-05-08T16:42:25.387 回答