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.

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

<h1><%= @team.name %></h1> <% if !...@team.players.empty? %>   <h3>Roster</h3>   <%= link_to ' (Shirt Report)',               :action => 'shirt_report',               :id => @team %>   <div class="indent">   <table> ... ...

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.

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.

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

<h1><%= @team.name %></h1> <% if !@team.players.empty? %>   <h3>Roster</h3>   <%= link_to ' (Shirt Report)',               :action => 'shirt_report',               :id => @team %>   <div class="indent">   <table>     <thead><td>Player Name</td><td>Height</td><td>Weight</td></thead>     <tbody>     <% @team.players.each do |player| %>       <tr>         <td>           <%= link_to h(player.last_name) + ', ' + 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

        </td>         <td>           <%= h player.height %>         </td>         <td>           <%= h player.weight %>         </td>       </tr>     <% end %>     </tbody>   </table>   </div> <% end %>

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

View: shirt_report.rhtml

<h3><%= @team.name %> Shirt Report</h3> <div class="indent"> <table>   <thead><td>Player Name</td><td>Shirt Size</td></thead>   <tbody>   <% @players.each do |player| %>     <tr>       <td>         <%= link_to h(player.last_name) + ', ' + h(player.first_name),                     :controller => 'player',                     :action => 'show',                     :id => player %>       </td>       <td>         <%= h player.shirt_size %>       </td>     </tr>   <% end %>   </tbody> </table> </div>

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

-Adam Klunick

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

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