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 trial

Ruby

Justin Whedon
Justin Whedon
19,811 Points

'undefined method `title' for nil:NilClass' Error

I'm getting this error... but everything was working fine up until this point.

In 'Rails Routes & Resources: Creating a View'.

undefined method `title' for nil:NilClass Extracted source (around line #1): 1 <h1><%= @page.title %></h1> 2 3 4 <p><%= @page.body %></p>


Screenshot of my .rb & .erb files

Justin Whedon
Justin Whedon
19,811 Points

I cannot move forward on my Ruby Track until I get this figured out. Anyone?

3 Answers

Lee Vaughn
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Lee Vaughn
Treehouse Teacher

Thanks!

Not sure if this is the only issue since I am not able to run your code but at least part of the issue is that you have a small syntax difference in your show method (page rather than Page). Try fixing that and see what happens.

Justin Whedon
Justin Whedon
19,811 Points

BAM!! That was 100% the problem. Not sure how I missed that :/

Thank you so much Lee!!!

Lee Vaughn
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Lee Vaughn
Treehouse Teacher

Been there done that Justin! Those little things often seem to be the hardest to spot.

Glad to have helped and happy coding!

Lee Vaughn
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Lee Vaughn
Treehouse Teacher

Hi Justin Whedon!

Which video are you currently working on/having trouble with? In your post, you mention the "Creating a View" lesson but in that video all Jay does is add an H1 header in the index.html.erb template. You have more code than that in your screenshots so I am not quite sure where you are in the course and where you started running into problems.

Also, can you share a link to a GitHub repo or a Snapshot of your Workspace so that we can see, test, and troubleshoot the code first hand?

Thanks!