# How Should I Fix a NoMethodError?

**URL:** <https://www.ruby-forum.com/t/how-should-i-fix-a-nomethoderror/91829>\
**Category:** Rails\
**Created:** [April 12, 2007, 6:28pm UTC](https://www.ruby-forum.com/t/how-should-i-fix-a-nomethoderror/91829 "2007-04-12T18:28:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zkidd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5e925/32.png) [@Zkidd](https://www.ruby-forum.com/u/Zkidd)\
**Post date:** [April 12, 2007, 6:28pm UTC](https://www.ruby-forum.com/t/how-should-i-fix-a-nomethoderror/91829/1 "2007-04-12T18:28:39Z")

</div>

I am getting a NoMethodError in the show.rhtml file around an  
@story.user.login variable. But I checked the controller and the  
rhtml file and it looks like things are ok. This is the error message:

NoMethodError in Story#show

Showing app/views/story/show.rhtml where line #20 raised:

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.login  
Extracted source (around line #20):

17:

  
18: 

19: Submitted by:  
20: \<%= @story.user.login %\>  
21:

  
22: 
  
23: \<%= link\_to\_remote ‘shove it’,  
RAILS\_ROOT: script/…/config/…

Application Trace | Framework Trace | Full Trace  
#{RAILS\_ROOT}/app/views/story/show.rhtml:20:in  
`_run_rhtml_47app47views47story47show46rhtml' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/ base.rb:326:in`send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action\_view/  
base.rb:326:in `compile_and_render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/ base.rb:301:in`render\_template’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action\_view/  
base.rb:260:in `render_file' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/base.rb:806:in`render\_file’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/base.rb:711:in `render_with_no_layout' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/layout.rb:247:in`render\_without\_benchmark’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/benchmarking.rb:50:in `render' /usr/local/lib/ruby/1.8/benchmark.rb:293:in`measure’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/benchmarking.rb:50:in `render' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/base.rb:1096:in`perform\_action\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/filters.rb:632:in `call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:634:in`call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/filters.rb:638:in `call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:438:in`call’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/filters.rb:637:in `call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:619:in`perform\_action\_without\_benchmark’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/benchmarking.rb:66:in  
`perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in`measure’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/benchmarking.rb:66:in  
`perform_action_without_rescue' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/rescue.rb:83:in`perform\_action’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/base.rb:430:in `send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/base.rb:430:in`process\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/filters.rb:624:in  
`process_without_session_management_support' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/session_management.rb:114:in`process’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/base.rb:330:in `process' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/dispatcher.rb:41:in`dispatch’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/webrick\_server.rb:  
113:in `handle_dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/webrick_server.rb: 79:in`service’  
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in`run’  
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in`start’  
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in`start’  
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in `each' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in`start’  
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in`start’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/webrick\_server.rb:  
63:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/commands/servers/ webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`gem\_original\_require’  
/usr/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/ active_support/dependencies.rb:495:in`require’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/  
active\_support/dependencies.rb:342:in `new_constants_in' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/ active_support/dependencies.rb:495:in`require’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/commands/server.rb:  
39  
/usr/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’  
script/server:3  
Request

Parameters: {“permalink”=\>“my-shiny-weblog”}

Show session dump

Response

Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}

---

<div class="post-metadata">

**Author:** ![Zkidd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5e925/32.png) [@Zkidd](https://www.ruby-forum.com/u/Zkidd)\
**Post date:** [April 12, 2007, 6:34pm UTC](https://www.ruby-forum.com/t/how-should-i-fix-a-nomethoderror/91829/2 "2007-04-12T18:34:41Z")

</div>

essentially your @story doesn’t have a user. Either force the story to  
have  
a user, or add a condition to your printout statement.

\<%= @story.user.login unless @story.user.nil? %\>

you will receive this message any time you try to call a method against  
a  
nil object so it is important to either assign a blank user to your  
story  
any time you view this page, or start checking that the user isn’t nil,  
like  
the sample above.

On 4/12/07, Zkidd [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You have a nil object when you didn’t expect it!  
> RAILS\_ROOT: script/…/config/…  
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action\_view/  
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
> action\_controller/filters.rb:438:in `call' `perform\_action\_without\_rescue’  
> action\_controller/session\_management.rb:114:in `process' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start\_thread’  
> webrick.rb:59  
> /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/commands/server.rb:  
> Show session dump
> 
> Response
> 
> Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}
> 
> >

–  
Mike W.  
Web D.  
UW-Eau Claire

---

<div class="post-metadata">

**Author:** ![Zkidd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5e925/32.png) [@Zkidd](https://www.ruby-forum.com/u/Zkidd)\
**Post date:** [April 12, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/how-should-i-fix-a-nomethoderror/91829/3 "2007-04-12T18:39:41Z")

</div>

Ok. . . and I am really new here, but first where would I find my  
“printout statement” and second, I raked my databases and got a rake  
aborted! uninitialized constant CreateUse as a result. Are these two  
issues related? Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Zkidd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5e925/32.png) [@Zkidd](https://www.ruby-forum.com/u/Zkidd)\
**Post date:** [April 12, 2007, 6:46pm UTC](https://www.ruby-forum.com/t/how-should-i-fix-a-nomethoderror/91829/4 "2007-04-12T18:46:42Z")

</div>

when I say printout statement, I’m referring to any time that you use  
\<%=  
“something” %\> since it prints a result to your html.

as far as your rake problem goes, it sounds like maybe your rake file  
isn’t  
named correctly. if your file name is 001\_create\_users.rb, within that  
file  
the class name must be CreateUsers. most likely your file is named  
(ignoring the version number) 001\_create\_use.rb, so it’s looking for a  
class  
name of CreateUse within the file. you need to make sure that the class  
name and file name agree.

On 4/12/07, Zkidd [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > \<%= @story.user.login unless @story.user.nil? %\>
> > 
> > > Showing app/views/story/show.rhtml where line #20 raised:  
> > > 22:
> > > 
> > >   
> > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action\_view/  
> > > action\_controller/benchmarking.rb:50:in `render' action_controller/filters.rb:638:in `call\_filter’  
> > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
> > > `process_without_session_management_support' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service’  
> > > 63:in `dispatch’  
> > > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/  
> > > Parameters: {“permalink”=\>“my-shiny-weblog”}  
> > > UW-Eau Claire
> 
> >

–  
Mike W.  
Web D.  
UW-Eau Claire

---

<div class="post-metadata">

**Author:** ![Zkidd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b5e925/32.png) [@Zkidd](https://www.ruby-forum.com/u/Zkidd)\
**Post date:** [April 12, 2007, 6:41pm UTC](https://www.ruby-forum.com/t/how-should-i-fix-a-nomethoderror/91829/5 "2007-04-12T18:41:42Z")

</div>

Wow… . . that worked! I replaced your line with mine in the rhtml.  
But I am still curious about the rake thing. Thanks.
