NoMethodError:nil的未定义方法new:NilClass

时间:2011-06-12 01:55:33

标签: ruby-on-rails

尝试在rails控制台中输入list = list.new时遇到问题。我收到以下错误消息:

NoMethodError: undefined method `new’ for nil:NilClass
from /Users/csamanian/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.8/lib/active_support/whiny_nil.rb:48:in `method_missing’
from (irb):1
from /Users/csamanian/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands/console.rb:44:in `start’
from /Users/csamanian/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands/console.rb:8:in `start’
from /Users/csamanian/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands.rb:23:in `’
from script/rails:6:in `require’
from script/rails:6:in `’

任何想法为什么? 非常感谢!

2 个答案:

答案 0 :(得分:5)

模型名称在Rails中按惯例大写。试试这个:

list = List.new

答案 1 :(得分:0)

你应该试试这个

@list = List.new