简体   繁体   English

Rails 3 Rails控制台Test.new不起作用

[英]Rails 3 Rails Console Test.new doesn't work

I created a scaffold in Rails 3 and ran the migration. 我在Rails 3中创建了一个脚手架并运行了迁移。 But when I tried to use the rails console to create an instance of the model, it doesn't work. 但是当我尝试使用rails控制台创建模型的实例时,它不起作用。 I repeated the same process in Rails 4 and it works perfectly. 我在Rails 4中重复了相同的过程,它完美无缺。 Here is the commands I typed in. 这是我输入的命令。

rails new testApp rails g scaffold Test name:string rake db:migrate rails console p = Test.new rails new testApp rails g scaffold测试名称:string rake db:migrate rails console p = Test.new

and below is the response I got: 1.9.3p194 :002 > p = Test.new NoMethodError: undefined method new' for Test:Module from (irb):2 from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.15/lib/rails/commands/console.rb:47:in start' from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.15/lib/rails/commands/console.rb:8:in start' from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.15/lib/rails/commands.rb:41:in ' from script/rails:6:in require' from script/rails:6:in ' 以下是我得到的响应:1.9.3p194:002> p = Test.new NoMethodError:未定义的方法new'for new' for Test:Module from (irb):2 from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.15/lib/rails/commands/console.rb:47:in /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2。 15 / lib / rails / commands / console.rb:8:in start' from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.15/lib/rails/commands.rb:41:in in'from script / rails:6:in require' from script/rails:6:in '

Please help. 请帮忙。 I am a beginner in rails. 我是铁轨的初学者。 Thank you. 谢谢。

Test is a module of Unit testing. Test是单元测试的一个模块。 When you type it in console, this constant get shown instead of your own model. 当您在控制台中键入它时,将显示此常量而不是您自己的模型。

The only lesson is to avoid using sensitive names in your app's constant names. 唯一的教训是避免在应用程序的常量名称中使用敏感名称。

有关保留关键字的完整列表,请访问: http//reservedwords.herokuapp.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM