Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDavid Thrower
6,693 PointsConsole gives me NameError: undefined local variable or method `page' for main:Object on > page.title = "lorem ipsum"
OK so i follow all the steps to here verbatim with the same results up to here. The controller and model are there, the migration has been run, and etc. I get to the console to add dummy records:
$ rails c
....
> Page.all
"Page Load (1.4ms) SELECT "pages".* FROM "pages"
=> #<ActiveRecord::Relation []>"
> Page.new
-> <Page id: nil, title: nil, body: nil, slug: nil, created_at: nil, updated_at: nil>
page.title = "lorem ipsum"
-> NameError: undefined local variable or method `page' for main:Object
(then lots of stack tracings)
Yes, I did check that the capitalization / pluralization is correct. Anyone know what this is wrong?
1 Answer
Steve Hunter
57,712 PointsHi David,
Did you get this fixed?
From what I can see, you have not assigned your new Page instance into the variable page
so when you try to set the title
attribute, the console doesn't know what page
is.
To fix this, assign the result of calling new
into page
:
page = Page.new
I hope that helps.
Steve.