0

I have been following this tutorial, http://ruby.railstutorial.org/chapters/modeling-users?version=3.2#top, and I tried this in the rails console

User.new(name: "Michael Hartl", email: "[email protected]")
SyntaxError: compile error

but when I tried this it worked:

User.new(:name=> "Michael Hartl", :email=>"[email protected]")
=> #<User id: nil, name: "Michael Hartl", email: "[email protected]", created_at: nil, updated_at: nil>

I am using rails 3.2.1, which I guess this is the problem, but why change the syntax to something more complicated like, :<variable>=> instead of <variable>: ??

1 Answer 1

1

You didn't type it correctly.

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

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

2 Comments

sorry, my mistake. It was "User.new(name: "Michael Hartl", email: "[email protected]")" ! So the question remains#
If you aren't using Ruby 1.9+ then you can't use the new hash syntax.

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.