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
M Myers
918 PointsTreebook nil error
Hi,
I'm working on "Build a Simple Ruby on Rails Application". I can't seem to fix an error in index.html.erb. When I try to load the page, it seems status.user is always nil, so when I try to get the user's full name (status.user.full_name) or gravatar (status.user.gravatar_url), I always get the following error: "undefined method `gravatar_url' for nil:NilClass"
And, yes, full_name and gravatar_url both exist in User. Anyone have any idea how to fix this?
Thanks for any help.
9 Answers
M Myers
918 PointsThanks for the help, Jason. I redid that video without luck and after ensuring all my code was right, the final suspect was the database. Looks like my database was missing user_id. For anyone having a similar problem, I just deleted the database and redid the migration, like this:
rake db:drop rake db:create rake db:migrate
But keep in mind db:drop WILL delete everything so be wary if there's any info you don't want deleted.
Jason Seifer
Treehouse Guest TeacherTry following along with Jim in this video and let us know if that fixes the problem: http://teamtreehouse.com/library/programming-2/build-a-simple-version-of-facebook/customizing-forms/getting-the-latest-changes. Thanks!
Jason Seifer
Treehouse Guest TeacherGlad you got it sorted out, M!
Dan Pereda
968 PointsFor others I fixed my issue by running rake db:reset then rake db:migrate. you may have to put bundle exec in front of those commands.
Jason Seifer
Treehouse Guest TeacherThanks, Dan Pereda!
Shawn Hurd
Courses Plus Student 4,616 PointsI tried everything posted here and still get the error. After entering "rake db:reset" I fell into a much bigger problem where nothing was working and everything caused errors but I was able to fix that with "rake db:test:prepare". but now I'm back to square 1.
I've watched and rewatched the videos and cross-referenced between the downloadable project files and my own and everything appears to be in order.
I'm not sure what else to do and some help would be appreciated.
Jason Seifer
Treehouse Guest TeacherHey Shawn Hurd try running the following:
rake db:reset
rake db:migrate
rake db:rest:prepare
Also, it would be really helpful if you could post the errors you get.
Shawn Hurd
Courses Plus Student 4,616 PointsThis is the error I get when I enter the "status_controller_test" test command. I've already tried the commands you suggested.
C:\Sites\shawnbook\shawnbook>ruby -Itest test/functional/statuses_controller_test.rb Run options:
Running tests:
.......E......
Finished tests in 0.526031s, 26.6144 tests/s, 43.7237 assertions/s.
1) Error:
test_should_get_index(StatusesControllerTest):
ActionView::Template::Error: undefined method gravatar_url' for nil:NilClass
C:/Sites/shawnbook/shawnbook/app/views/statuses/index.html.erb:11:inblock
in app_views_statuses_index_html_erb526674503_44841312'
C:/Sites/shawnbook/shawnbook/app/views/statuses/index.html.erb:7:in each'
C:/Sites/shawnbook/shawnbook/app/views/statuses/index.html.erb:7:in_app_vi
ews_statuses_index_html_erb_526674503_44841312'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/template.rb:145:in block in render'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/li
b/active_support/notifications.rb:123:inblock in instrument'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/li
b/active_support/notifications/instrumenter.rb:20:in instrument'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/li
b/active_support/notifications.rb:123:ininstrument'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/template.rb:143:in render'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/renderer/template_renderer.rb:47:inblock (2 levels) in render_templ
ate'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/renderer/abstract_renderer.rb:38:in block in instrument'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/li
b/active_support/notifications.rb:123:inblock in instrument'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/li
b/active_support/notifications/instrumenter.rb:20:in instrument'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/li
b/active_support/notifications.rb:123:ininstrument'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/renderer/abstract_renderer.rb:38:in instrument'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/renderer/template_renderer.rb:46:inblock in render_template'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/renderer/template_renderer.rb:54:in render_with_layout'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/renderer/template_renderer.rb:45:inrender_template'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/renderer/template_renderer.rb:18:in render'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/renderer/renderer.rb:36:inrender_template'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_view/renderer/renderer.rb:17:in render'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
bstract_controller/rendering.rb:110:in_render_template'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_controller/metal/streaming.rb:225:in _render_template'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
bstract_controller/rendering.rb:103:inrender_to_body'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_controller/metal/renderers.rb:28:in render_to_body'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_controller/metal/compatibility.rb:50:inrender_to_body'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
bstract_controller/rendering.rb:88:in render'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_controller/metal/rendering.rb:16:inrender'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/a
ction_controller/metal/instrumentation.rb:40:in block (2 levels) in render'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/li
b/active_support/core_ext/benchmark.rb:5:inblock in ms'
14 tests, 23 assertions, 0 failures, 1 errors, 0 skips
Jason Seifer
Treehouse Guest TeacherHey Shawn Hurd please zip up your project files and email it to help@teamtreehouse.com and I'll take a look. Thanks!
Brian Han
Courses Plus Student 3,959 PointsBrian Han
Courses Plus Student 3,959 PointsThank you! I was having a database problem issue too and I got it sorted out doing the rake commands you posted here.
Cheers!