Rails Console does not load the methods and classes of my application, why?

2

I have a model named Person, when I open the Rails Console and try to assign it to any variable, I get this:

user.localapp (test) $ rails c
Loading development environment (Rails 4.2.0) (Ruby 2.2.0)
localapp> a = person.first
NameError: undefined local variable or method 'person' for main:Object
from (irb):1

Does anyone know why?

    
asked by anonymous 12.05.2015 / 19:04

2 answers

2

Use Person (first letter uppercase) instead of person (first lowercase letter)

a = Person.first
    
12.05.2015 / 20:25
2

person is a variable that does not exist. You have to call the class method:

person = Person.first

This will bring you the first Person of your database.

    
12.05.2015 / 19:30