[英]Rails 3 Rails Console Test.new doesn't work
我在Rails 3中创建了一个脚手架并运行了迁移。 但是当我尝试使用rails控制台创建模型的实例时,它不起作用。 我在Rails 4中重复了相同的过程,它完美无缺。 这是我输入的命令。
rails new testApp rails g scaffold测试名称:string rake db:migrate rails console p = Test.new
以下是我得到的响应: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
'
请帮忙。 我是铁轨的初学者。 谢谢。
Test
是单元测试的一个模块。 当您在控制台中键入它时,将显示此常量而不是您自己的模型。
唯一的教训是避免在应用程序的常量名称中使用敏感名称。
有关保留关键字的完整列表,请访问: http : //reservedwords.herokuapp.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.