0

When I open Rails console, or sandbox for that matter, and I try and add new date, in this case, a user, I keep getting this same error. I have tried everything to get it resolved, but for the life of me I cannot figure it out. I am using Windows, so obviously I know that is one of my first problems, but its all I have for the current moment, so I will have to make due. Here is the error message that pops up when I try and simply enter user.new(information...)... any help would be greatly appreciated, I am pulling my hair out over here.

    C:\TTS\Rails\workspace\sample_app>rails console
    DL is deprecated, please use Fiddle
    Loading development environment (Rails 4.2.0)
    irb(main):001:0> user.new(name: "Will Wagar", email: "[email protected]")
    NameError: undefined local variable or method `user' for main:Object
            from (irb):1
            from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
            from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
            from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
            from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
            from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
            from bin/rails:4:in `require'
            from bin/rails:4:in `<main>'
3
  • If you don't like using windows to do development, try running ubuntu using a VM. Commented Feb 12, 2015 at 21:07
  • I am considering doing that with all the problems I am running into with this current setup, I probably should just bite the bullet and get it over with. Commented Feb 12, 2015 at 21:10
  • 2
    It is User.new with a uppercase U. Commented Feb 12, 2015 at 21:25

2 Answers 2

1

You almost certainly want User.new (note the capital U) rather than user.new, it's a Ruby convention that classes are capitalised.

To expand, you probably want to do it in several steps:

user = User.new(name: "Will Wagar", email: "[email protected]")
user.valid?
user.save
etc...

So in the first one you're creating an instance of the class User and assigning it to the variable user and then in subsequent operations, you're working with the new user variable you've created.

Sign up to request clarification or add additional context in comments.

2 Comments

I see that now, but even when I try and see if it is valid or save it I get the same error, capitalized or not.
I've expanded my answer above to explain where I think the problem is
0

I see that now, I should have mentioned in the question that I have tried it both ways, capitalized and not. I can get a return when I try it with a capital U, but when I try and check to see if it is valid or save it, I get the same error. irb(main):008:0> user.valid? NameError: undefined local variable or method user' for main:Object from (irb):8 from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:instart' from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in start' from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:inconsole' from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in run_command!' from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in' from bin/rails:4:in require' from bin/rails:4:in'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.