我正在尝试测试在sqlite3 db中插入一行,对于第7章中的Rails教程。我已经多次查看代码并且它看起来是正确的,但是在控制台中我收到以下错误。有什么建议?
User.create(name =>“test user”,:email =>“testuser@example.com”,:password =>“foobar”,:password_confirmation =>“foobar”) ArgumentError:参数数量错误(0表示1) 来自/Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:442:in
maximum' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:442:in
发送' from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:442:inmaximum' from /Users/gabemcmillan/rails_projects/sample_app/app/models/user.rb:10 from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in
load' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:inload_file' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in
new_constants_in' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:453:inload_file' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:340:in
require_or_load' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:491:inload_missing_constant' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:183:in
const_missing' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:181:ineach' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:181:in
const_missing' 来自(irb):8
答案 0 :(得分:3)
应为User.create(:name...
(name
之前有冒号),而不是User.create(name...