我在RVM等中使用Rails 3.2.12和Roby 2.0.0-p0。rails console
我在执行u = Users.first
后收到以下错误:
u = Users.first
Loading production environment (Rails 3.2.12)
2.0.0p0 :001 > u = Users.first
NoMethodError: undefined method `first' for Users:Module
from (irb):1
from /usr/local/rvm/gems/ruby-2.0.0-p0@discourse/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p0@discourse/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p0@discourse/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我能够访问数据库并使用用户rails将使用的psql控制台查看记录。
答案 0 :(得分:3)
如果您已经定义了用户模型,请尝试使用User.first而不是Users.first。