Hi all,

I have two classes: a player class and a game class. Each game has two
player IDs. I would like the game show view to be able to display each
player's full name via a method, as follows:
<%=h Player.get_player_name(@game.player2) %>

Here is the method definition in my players controller:
  def get_player_name(playerID)
    @player = Player.find(playerID)
    @playerName = @player.firstName + " " + @player.lastName
  end

When I try to view the page, I get the error:
 Showing app/views/games/show.html.erb where line #8 raised:

undefined method `get_player_name' for #<Class:0x252de68>

Extracted source (around line #8):

5:
6: <p>
7:   <b>Player2:</b>
8:   <%=h Player.get_player_name(@game.player2) %>
9: </p>
10:
11: <p>

I can call the get_player_name method from a player view. Clearly I
don't understand something about how rails does its scoping, but I am
not sure where to look. For instance, I don't see anything in my
Learning Rails book that might explain how this works.

My question is: where can I put my get_player_name method so that it
can be accessed by other classes as well?

I am actually surprised that I can't access the method, because the
following does work from within my game show view:
<%=h Player.find(@game.player1).firstName + " " +
Player.find(@game.player1).lastName %>

Thanks,
Stu

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to