views:

194

answers:

2

Hi there!

I am working with a book to teach myself Ruby-on-Rails. Ruby version is 1.2.3 and rubygems V 1.3.5.

I start the console by ruby script/console and enter:

user = User.new(:screen_name => "example",
?> :email => "exampleATexample.com",
?> :password => "example")

but instead of adding the data to the DB, I get the following:

NameError: undefined local variable or method 'within' for User:Class from D:/ruby/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1235:in 'method_missing' from ./script/../config/../config/../app/modules/user.rb:13

I don't really understand what's going on. Any kind of help is much appreciated, thank you!

A: 

First, I believe you main Rails v 1.2.3, this is a very old version of Rails, don't use it.

Second thing, the command you entered has wrong Ruby syntax... try this instead:

user =User.new(:screen_name => "example", :email => "exampleATexample.com", :password => "example")

Third thing: please paste more code....

khelll
The command was correct syntax, he just entered it over multiple lines and forgot to remove the prompts. But yes, you should install a newer version of rails, it's at version 2.3.5 now. (`gem install rails`).
dvyjones
Thank you khelll for taking your time answering. You are right, there is more code to it. I can't copy and paste from the shell as it doesn't allow me to. I didn't expect the code to matter that much, but since you pointed to it missing, thank you for making clear to me how important every single bit of code for you guys is to help solving problems. I will keep that in mind. Thank you once again for helping.
A: 

Also, just as a check.

Whenever something doesn't work in Rails that has to do with the database, make sure you run

rake db:migrate

Sometimes this can slip your mind and cause weird errors.

Also, just as a side note... I would make sure that you add some validations to your user model that requires a user to confirm their password and or email. It's generally a good practice.

validates_confirmation_of :password, :email

All the best with learning Rails. Make sure you take @dvyjones's advice and upgrade to the latest version of Rails... a lot has changed since v. 1.2.3

ewakened
Thank you for taking your time to offer a piece of advice. The book's accompanying website says that to avoid trouble, it's best to stick with the book's version of rails (you are right, not ruby :-) ). But since I ran into trouble already sticking to the old version, I might just as well upgrade and work through all the problems with the community. So, I will upgrade.
Which book is it? I ask only because Rails is a framework where not only the code changes but so do the best practices. Using an older book is good for a start but I would recommend trying to stay more current. No problem with the help. If you need anything else track me down on twitter, @kentf
ewakened