Вопрос

I created a scaffold in Rails 3 and ran the migration. But when I tried to use the rails console to create an instance of the model, it doesn't work. I repeated the same process in Rails 4 and it works perfectly. Here is the commands I typed in.

rails new testApp rails g scaffold Test name: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:instart' 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'

Please help. I am a beginner in rails. Thank you.

Это было полезно?

Решение

Test is a module of Unit testing. 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.

Другие советы

For a full list of reserved keywords check out: http://reservedwords.herokuapp.com/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top