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:in
new' 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:insubstitute_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: in
block 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: ineach' 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_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: insubstitute_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: in
insert' 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:in
block 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:incall' 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:ins 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:in
console' 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:inrun_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:inrequire' 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
block 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: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:252:in
require' 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: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:246:inblock 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: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:246:inload' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in
require' from /Users/Jonathon/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:inrequire' 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!
user = User.create(options)
instead ofuser = User.new(options)
anduser.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