# NoMethodError in Stories#show

**URL:** <https://www.ruby-forum.com/t/nomethoderror-in-stories-show/176397>\
**Category:** Rails\
**Created:** [September 30, 2009, 1:34am UTC](https://www.ruby-forum.com/t/nomethoderror-in-stories-show/176397 "2009-09-30T01:34:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dangermoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Post date:** [September 30, 2009, 1:34am UTC](https://www.ruby-forum.com/t/nomethoderror-in-stories-show/176397/1 "2009-09-30T01:34:41Z")

</div>

I’m a Rails newbie and am working my way through Simply Rails 2 by  
Patrick Lenz.

Have run into a problem on page 207 of the book; this is the error I  
run into when I fire up my server and open up httpL//localhost:3000/  
stories/new I have posted the error message and trace below.

Thanks in advance for your help.

* * *

Showing app/views/stories/show.html.rb where line #1 raised:

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

1:

## \<%= @story.name %\>
  
2: 

\<%= link\_to @story.link, @story.link %\>

  
RAILS\_ROOT: /Users/pdenlinger/Sites/In\_Development/shovell

Application Trace | Framework Trace | Full Trace  
app/views/stories/show.html.rb:1  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_view/  
renderable.rb:39:in `send' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/ renderable.rb:39:in`render’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_view/  
template.rb:73:in `render_template' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/base.rb: 256:in`render’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_view/base.rb:  
367:in `_render_with_layout' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/base.rb: 254:in`render’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
base.rb:1174:in `render_for_file' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/ base.rb:896:in`render\_without\_benchmark’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
benchmarking.rb:51:in `render' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/ core_ext/benchmark.rb:8:in`realtime’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
benchmarking.rb:51:in `render' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/ base.rb:868:in`render\_without\_benchmark’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
benchmarking.rb:51:in `render' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/ core_ext/benchmark.rb:8:in`realtime’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
benchmarking.rb:51:in `render' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/ base.rb:1248:in`default\_render’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
base.rb:1259:in `perform_action_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/ filters.rb:617:in`call\_filters’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
filters.rb:610:in `perform_action_without_benchmark' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/ benchmarking.rb:68:in`perform\_action\_without\_rescue’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
benchmarking.rb:68:in `perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/ rescue.rb:136:in`perform\_action\_without\_caching’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
caching/sql\_cache.rb:13:in `perform_action' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/ connection_adapters/abstract/query_cache.rb:34:in`cache’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active\_record/  
query\_cache.rb:8:in `cache' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/ caching/sql_cache.rb:12:in`perform\_action’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
base.rb:524:in `send' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/ base.rb:524:in`process\_without\_filters’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
filters.rb:606:in `process_without_session_management_support' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/ session_management.rb:134:in`process’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/  
base.rb:392:in `process' /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/webrick_server.rb:74:in`service’  
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/servers/  
webrick.rb:66  
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active\_support/  
dependencies.rb:153:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/ dependencies.rb:521:in`new\_constants\_in’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active\_support/  
dependencies.rb:153:in `require’  
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49

---

<div class="post-metadata">

**Author:** ![dangermoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Post date:** [September 30, 2009, 2:32am UTC](https://www.ruby-forum.com/t/nomethoderror-in-stories-show/176397/2 "2009-09-30T02:32:03Z")

</div>

On Tue, Sep 29, 2009 at 6:32 PM, removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> Showing app/views/stories/show.html.rb where line #1 raised:

In your “stories” controller, in your “show” method, are instantiating  
a @story object? Do you see something like

@story = Story.find(…)

?

> You have a nil object when you didn’t expect it!  
> The error occurred while evaluating nil.name  
> Extracted source (around line #1):
> 
> 1:
> 
> ## \<%= @story.name %\>

Cause down here in your view you seem to be expecting one.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![dangermoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Post date:** [September 30, 2009, 10:12am UTC](https://www.ruby-forum.com/t/nomethoderror-in-stories-show/176397/3 "2009-09-30T10:12:11Z")

</div>

2009/9/30 removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> * * *
> 
> Showing app/views/stories/show.html.rb where line #1 raised:
> 
> You have a nil object when you didn’t expect it!  
> The error occurred while evaluating nil.name  
> Extracted source (around line #1):
> 
> 1:
> 
> ## \<%= @story.name %\>

The error means that when it tries to display @story.name then @story  
is nil. This likely means that the find used to setup @story in your  
controller did not find a record.

I suggest having a look at the rails guide on Testing Rails Apps at  
[http://guides.rubyonrails.org/](http://guides.rubyonrails.org/) This may help you to work out what is  
wrong. In addition the Getting Started guide and ActiveRecord  
Associations are compulsory reading.

Colin

---

<div class="post-metadata">

**Author:** ![dangermoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Post date:** [September 30, 2009, 9:23am UTC](https://www.ruby-forum.com/t/nomethoderror-in-stories-show/176397/4 "2009-09-30T09:23:36Z")

</div>

Yes, I do have a method in the stories\_controller.rb file. I have  
copied the contents of the file below:

class StoriesController \< ApplicationController  
def index  
@story = Story.find(:first, :order =\> ‘RANDOM()’)  
end  
def new  
@story = Story.new  
end  
def create  
@story = Story.new(params[:story])  
if @story.save  
flash[:notice] = ‘Story submission succeeded’  
redirect\_to stories\_path  
else  
render :action =\> ‘new’  
end  
def show  
@story = Story.find(params[:id])  
end  
end  
end

Following is the content of the show.html.rb file:

## \<%= @story.name %\>

\<%= link\_to @story.link, @story.link %\>

Still not quite sure what is wrong.

Thanks!

---

<div class="post-metadata">

**Author:** ![dangermoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Post date:** [September 30, 2009, 11:14am UTC](https://www.ruby-forum.com/t/nomethoderror-in-stories-show/176397/5 "2009-09-30T11:14:50Z")

</div>

> ```
> if @story.save
> 
> ```
> 
> Following is the content of the show.html.rb file:
> 
> ## \<%= @story.name %\>
> 
> \<%= link\_to @story.link, @story.link %\>

Well if you are using routes like: \<% map.resources :stories %\>  
Then your show url should be like \<% http://[HTTP\_HOST]/stories/1/ %\>  
with HTTP GET method.  
If you are using ajax request then make sure you set the HTTP method  
to GET in your \<% link\_to\_remote %\> method.

And if you are not using routes then Manish already indicated a  
possibility 😃

Over all make sure you are getting the story id in your params[:id]  
variable in show action.

Hope you will be able to find out the problem 🙂  
Thank you.

Samiron paul

> **[Small Talk](https://samironpaul.blogspot.com/)**

> **[亚搏APP手机版-官方网站](http://www.scrumpad.com)**
>
> 亚搏app手机版下载是亚洲最具规模且成长最快的在线娱乐之一,当前国内最知名的游戏娱乐平台,汇聚了最新最热最好玩百款精彩游戏,国内最具影响力娱乐平台!

---

<div class="post-metadata">

**Author:** ![dangermoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Post date:** [September 30, 2009, 10:42am UTC](https://www.ruby-forum.com/t/nomethoderror-in-stories-show/176397/6 "2009-09-30T10:42:38Z")

</div>

Hey paul

can u paste your show url.

bcoz in your show method you have write

def show  
@story = Story.find(params[:id])  
end

your url must be…  
http//localhost:3000/stories/show/id

so please paste your show url where you get error.

Colin L. wrote:

> 2009/9/30 removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > * * *
> > 
> > Showing app/views/stories/show.html.rb where line #1 raised:
> > 
> > You have a nil object when you didn’t expect it!  
> > The error occurred while evaluating nil.name  
> > Extracted source (around line #1):
> > 
> > 1:
> > 
> > ## \<%= @story.name %\>
> 
> The error means that when it tries to display @story.name then @story  
> is nil. This likely means that the find used to setup @story in your  
> controller did not find a record.
> 
> I suggest having a look at the rails guide on Testing Rails Apps at  
> [http://guides.rubyonrails.org/](http://guides.rubyonrails.org/) This may help you to work out what is  
> wrong. In addition the Getting Started guide and ActiveRecord  
> Associations are compulsory reading.
> 
> Colin
