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

Asked

Viewed 190 times

2

I have a model called 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?

2 answers

2

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

person = Person.first

That’ll get you the first Person from your database.

2


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

a = Person.first

Browser other questions tagged

You are not signed in. Login or sign up in order to post.