# Very odd RoR behavior. Something is wrong here

**URL:** <https://www.ruby-forum.com/t/very-odd-ror-behavior-something-is-wrong-here/105959>\
**Category:** Rails\
**Created:** [June 4, 2007, 11:24pm UTC](https://www.ruby-forum.com/t/very-odd-ror-behavior-something-is-wrong-here/105959 "2007-06-04T23:24:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Klunick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@Adam\_Klunick](https://www.ruby-forum.com/u/Adam_Klunick)\
**Post date:** [June 4, 2007, 11:24pm UTC](https://www.ruby-forum.com/t/very-odd-ror-behavior-something-is-wrong-here/105959/1 "2007-06-04T23:24:44Z")

</div>

I have 2 different actions for a single controller (show and  
shirt\_report). Each action has its own view. I have included the  
code for each below. The problem is that I am receiving an error when  
generating shirt\_report, but not show, on my webserver running in  
production, but not on my laptop running in development. The error  
recieved is also listed below. Any help in clearing up this issue  
would be greatly appreciated.

================  
Controller:

class TeamController \< ApplicationController

def show  
@team = current\_user.teams.find(params[:id])  
end

def shirt\_report  
@team = current\_user.teams.find(params[:id])  
@players = @team.players.find(:all, :order =\> ‘last\_name ASC’)  
end

end

================

View: show.rhtml

# \<%= @team.name %\>
\<% if !@team.players.empty? %\> 
### Roster
 \<%= link\_to ' (Shirt Report)', :action =\> 'shirt\_report', :id =\> @team %\> 
 \<% @team.players.each do |player| %\> \<% end %\> 

| Player Name | Height | Weight |
| \<%= link\_to h(player.last\_name) + ', ' + h(player.first\_name), :controller =\> 'player', :action =\> 'show', :id =\> player %\> | \<%= h player.height %\> | \<%= h player.weight %\> |

\<% end %\>

================

View: shirt\_report.rhtml

### \<%= @team.name %\> Shirt Report

 \<% @players.each do |player| %\> \<% end %\> 

| Player Name | Shirt Size |
| \<%= link\_to h(player.last\_name) + ', ' + h(player.first\_name), :controller =\> 'player', :action =\> 'show', :id =\> player %\> | \<%= h player.shirt\_size %\> |

================

The error when clicking on one of the links generated in show to get  
to the shirt\_report:

ActionView::TemplateError (undefined method `name’ for nil:NilClass)  
on line #1 of app/views/team/shirt\_report.rhtml:  
1:

### \<%= @team.name %\> Shirt Report
  
2: 
  
3:   
4: 

```
#{RAILS_ROOT}/app/views/team/shirt_report.rhtml:1:in

```

`_run_rhtml_47app47views47team47shirt_report46rhtml' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_view/base.rb:326:in`send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_view/base.rb:326:in `compile_and_render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_view/base.rb:301:in`render\_template’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_view/base.rb:260:in `render_file' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/base.rb:806:in`render\_file’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/base.rb:711:in `render_with_no_layout' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/layout.rb:247:in`render\_without\_benchmark’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/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.3/lib/  
action\_controller/benchmarking.rb:50:in `render' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/base.rb:1101:in`perform\_action\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:632:in `call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:638:in`call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:438:in `call' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:637:in`call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/filters.rb:619:in `perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/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.3/lib/ action_controller/benchmarking.rb:66:in`perform\_action\_without\_rescue’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/rescue.rb:83:in `perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/base.rb:430:in`send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/base.rb:430:in `process_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/filters.rb:624:in`process\_without\_session\_management\_support’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/session\_management.rb:114:in `process' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/base.rb:330:in`process’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:  
41:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/fcgi_handler.rb: 168:in`process\_request’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/fcgi\_handler.rb:  
143:in `process_each_request!' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/fcgi_handler.rb: 109:in`with\_signal\_handler’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/fcgi\_handler.rb:  
142:in `process_each_request!' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in`each\_cgi’  
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in  
`each' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in`each\_cgi’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/fcgi\_handler.rb:  
141:in `process_each_request!' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/fcgi_handler.rb: 55:in`process!’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/fcgi\_handler.rb:  
25:in `process!’  
dispatch.fcgi:24

================

-Adam Klunick

| Player Name | Shirt Size |

---

<div class="post-metadata">

**Author:** ![Adam\_Klunick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@Adam\_Klunick](https://www.ruby-forum.com/u/Adam_Klunick)\
**Post date:** [June 4, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/very-odd-ror-behavior-something-is-wrong-here/105959/2 "2007-06-04T23:35:45Z")

</div>

Production doesnt have the same ‘team’ data that development has?

- Richard

---

<div class="post-metadata">

**Author:** ![Adam\_Klunick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@Adam\_Klunick](https://www.ruby-forum.com/u/Adam_Klunick)\
**Post date:** [June 4, 2007, 11:48pm UTC](https://www.ruby-forum.com/t/very-odd-ror-behavior-something-is-wrong-here/105959/3 "2007-06-04T23:48:48Z")

</div>

If you notice, there is a reference to @team.name in both show and  
shirt\_report. Show works but shirt\_report does not.

---

<div class="post-metadata">

**Author:** ![Adam\_Klunick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@Adam\_Klunick](https://www.ruby-forum.com/u/Adam_Klunick)\
**Post date:** [June 5, 2007, 12:24am UTC](https://www.ruby-forum.com/t/very-odd-ror-behavior-something-is-wrong-here/105959/4 "2007-06-05T00:24:13Z")

</div>

Hi,  
In your show.rhtml you have:

View: show.rhtml

# \<%= @team.name %\>
\<% if !removed\_email\_address@domain.invalid? %\> 
### Roster
 \<%= link\_to ' (Shirt Report)', :action =\> 'shirt\_report', :id =\> @team %\> 
 ... ...

Your link\_to you have :id =\> @team, which should really be @team.id,  
otherwise you’re trying to pass the object @team, and not the id value  
for it.

John.

---

<div class="post-metadata">

**Author:** ![Adam\_Klunick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@Adam\_Klunick](https://www.ruby-forum.com/u/Adam_Klunick)\
**Post date:** [June 5, 2007, 12:53am UTC](https://www.ruby-forum.com/t/very-odd-ror-behavior-something-is-wrong-here/105959/5 "2007-06-05T00:53:16Z")

</div>

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

> ```
> :action => 'shirt_report',
> 
> ```
> 
> John.  
> Routes call an implicit #to\_param method on values, which is mapped to  
> #id on AR models by default. His code is fine, and has nothing to do  
> with the error.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![Adam\_Klunick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@Adam\_Klunick](https://www.ruby-forum.com/u/Adam_Klunick)\
**Post date:** [June 5, 2007, 1:09am UTC](https://www.ruby-forum.com/t/very-odd-ror-behavior-something-is-wrong-here/105959/6 "2007-06-05T01:09:18Z")

</div>

On Jun 4, 2007, at 5:24 PM, Adam Klunick wrote:

> Controller:  
> end  
> \<%= link\_to ’ (Shirt Report)',  
> h(player.first\_name),  
> :controller =\> ‘player’,  
> :action =\> ‘show’,  
> :id =\> player %\>  
> Are you talking about THIS link?  
> Because /player/show/:id seems to expect that the :id is for a TEAM,  
> not a player.

And the use of  
:id =\> some\_object  
calls the .to\_param method of some\_object which, by default, does .id

Perhaps you meant for for your controller action to be:  
def show  
@team = current\_user.teams.find(params[:id])  
@player = @team.players.find(params[:player])  
end

and in the view:  
\<%= link\_to player.full\_name,  
:controller =\> ‘player’,  
:action =\> ‘show’,  
:id =\> @team,  
:player =\> player %\>

And I’d suggest:  
class Player  
def roster\_name  
“#{self.last\_name}, #{self.first\_name}”  
end  
end

> Player NameShirt Size \<%= h player.shirt\_size %\> \<% end %\> 
> 
> ================
> 
> -Adam Klunick

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Adam\_Klunick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@Adam\_Klunick](https://www.ruby-forum.com/u/Adam_Klunick)\
**Post date:** [June 5, 2007, 1:13am UTC](https://www.ruby-forum.com/t/very-odd-ror-behavior-something-is-wrong-here/105959/7 "2007-06-05T01:13:18Z")

</div>

OR, should you show us the PlayerController#show as well?

On Jun 4, 2007, at 7:08 PM, Rob B. wrote:

> > recieved is also listed below. Any help in clearing up this issue
> > 
> > ```
> > <% @team.players.each do |player| %>
> > 
> > ```
> 
> and in the view:  
> end
> 
> > ```
> > <% end %>
> > 
> > ```
> > 
> > :id =\> player %\> ================
> > 
> > -Adam Klunick
> 
> -Rob
> 
> Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid  
+1 513-295-4739  
Skype: rob.biedenharn
