这是一个错误,但我调用了一些模型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>'
我该怎么办?
答案 0 :(得分: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