建立 post 资源后,数据库已经 migrate,并在 post.rb 中对字段进行了验证,跟着教程做了个下面的尝试, (以上操作步骤均正确) ranrandeMac-mini:blog ranran$ rails console Loading development environment (Rails 4.0.3) 进入 Irb 模式:::::::::::::::::::
irb(main):001:0> post /////就是这个尝试出现了下面的错误
NameError: undefined local variable or method post' for main:Object
from (irb):1
from /Users/ranran/blog/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/commands/console.rb:90:in
start'
from /Users/ranran/blog/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/commands/console.rb:9:in start'
from /Users/ranran/blog/vendor/bundle/ruby/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:62:in
'
from bin/rails:4:in require'
from bin/rails:4:in
不知道什么原因。
先 Post.count 显示 (55.4ms) SELECT COUNT(*) FROM posts
然后 Post 居然成功了!