1
votes

First off, bit of a noob with posting on here, so just let me know if my formatting is off or anything like that, I'll be happy to fix it :)

I've been following Michael Hartl's Rails Tutorial and its been great. I'm sure my issue is due to me not doing something properly, but I can't find anything on the web that would fix my problem.

I'm in Chapter 6 creating a user database. Everything works fine up until I try to do user.save

Just for reference, here's the steps leading up to the problem:

rails generate model User name:string email:string

and then:

bundle exec rake db:migrate 

open up a sandboxed console:

 rails console --sandbox

Make a new user

user = User.new(name: "Michael Hartl", email: "[email protected]")

Save it:

user.save

Everything gives me the expected outputs up until user.save which gives this

irb(main):002:0> user.save (0.1ms) SAVEPOINT active_record_1 (0.1ms) ROLLBACK TO SAVEPOINT active_record_1 ArgumentError: wrong number of arguments (1 for 0) from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adap ters/abstract_adapter.rb:271:in initialize' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adap ters/abstract_adapter.rb:271:innew' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adap ters/abstract_adapter.rb:271:in substitute_at' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:97: inblock in substitute_values' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96: in each' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96: ineach_with_index' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96: in substitute_values' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:56: ininsert' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb: 521:in _create_record' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/counter_cache.r b:139:in_create_record' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_metho ds/dirty.rb:122:in _create_record' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:30 6:inblock in _create_record' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb: 88:in call' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb: 88:in_run_callbacks' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb: 734:in _run_create_callbacks' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:30 6:in_create_record' ... 22 levels... from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.2.0.beta4/lib/rails/commands/console.rb:9:in s tart' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.2.0.beta4/lib/rails/commands/commands_tasks.rb: 68:inconsole' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.2.0.beta4/lib/rails/commands/commands_tasks.rb: 39:in run_command!' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.2.0.beta4/lib/rails/commands.rb:17:in' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies. rb:252:in require' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies. rb:252:inblock in require' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies. rb:237:in load_dependency' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies. rb:252:inrequire' from /Users/Jonathon/Documents/Aptana Studio 3 Workspace/RoR/bin/rails:8:in <top (required)>' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies. rb:246:inload' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies. rb:246:in block in load' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies. rb:237:inload_dependency' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta4/lib/active_support/dependencies. rb:246:in load' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:inrequire' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require' from -e:1:in'irb(main):003:0>

I've put my user.rb file here:

class User < ActiveRecord::Base end

and my create_users.rb file here as well

class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :name t.string :email t.timestamps null: false end end end

Thanks and let me know if there's anymore information I need to provide!

2
Does it give you an error if you run it in 'bundle exec rails console', without '--sandbox' ?roob
No it doesn't. Just loads the console like normaluser4087953
Your steps looks good; I just tried them and the call to #save worked fine. There's something messed up in your environment, but it's hard to tell what. Can you do anything to get a clean environment?slothbear
Hmm. I could try grabbing his commit of github. Lemme try thatuser4087953
Try the same steps but without passing the sandbox option to the rails console. Also try user = User.create(options) instead of user = User.new(options) and user.save just to see what happens. It's quite weird, to be honest. You might need to restart the tutorial and note any problems / problematic messages that you encounter.SHS

2 Answers

0
votes

Thanks for all the help guys!

Slothbear was right, ended up being a problem with my database. Cloned the tutorial git and the problems were solved.

0
votes

I got the same problem. At first I have ArgumentError when I tried user.save like you did. And then when I tried rake db:drop and then rake db:migrate, also I met the same error.

It was after bundle update for my case and I found this arel gem version makes the problem. It shows arel (6.0.0) on Gemfile.lock but when I tried arel (6.0.0.beta2) as like before, it worked.

I don't know why. I found this discussion though. Now we don't have problem with non-beta Rails 4.2.0, and no problem with Hartl tutorial if we don't bundle update on the sample app (as the author said)