how to add data to database from rails console

Posted by rails_guy on Stack Overflow See other posts from Stack Overflow or by rails_guy
Published on 2010-03-22T01:50:33Z Indexed on 2010/03/22 1:51 UTC
Read the original article Hit count: 320

Filed under:

I have a User model.

>> @u = User.new
=> #<User id: nil, userid: nil, password: nil, created_at: nil, updated_at: nil, user_first_name: nil, user_last_name: nil, user_status: nil, user_type: nil>

I am not able to add data to the Users table from the console. I am doing the following:

>> @u.userid="test1"
=> "test1"
>> @u.password="test2"
=> "test2"
>> @u.user_first_name="test3"
=> "test3"
>> @u.user_last_name="test4"
=> "test4"
>> @u.user_status="test5"
=> "test5"
>> @u.user_type="test6"
=> "test6"
>> @u.save
NoMethodError: undefined method `userid' for nil:NilClass

what am i doing wrong? I just simply want to add one row of data to the app.

© Stack Overflow or respective owner

Related posts about rails