Very odd RoR behavior. Something is wrong here

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 [email protected]? %>

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:insend’
/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:inrender_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:inrender_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:inrender_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:inmeasure’
/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:inperform_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:incall_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:incall_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:inperform_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:inperform_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:insend’
/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:inprocess_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:inprocess’
/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:inprocess_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:inwith_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:ineach_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:ineach_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:inprocess!’
/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

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

  • Richard

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

Hi,
In your show.rhtml you have:

View: show.rhtml

<%= @team.name %>

<% if [email protected]? %>

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.

On 6/4/07, John [email protected] 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://weblog.techno-weenie.net
http://mephistoblog.com

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
[email protected]

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
[email protected]

Rob B. http://agileconsultingllc.com
[email protected]
+1 513-295-4739
Skype: rob.biedenharn