Just learning the framework. I apologize if this is in the worng forum.
I looked around for something like “Beginner’s Questions” but didn’t see
I’m building a simple application which will let players register for an
So, I’ve generated a player_admin controller and pointed it to my
players table. Worked great, I’m off and running.
After learning about hashing the password, I decided I might like to add
a convenience method to the Player (attached) which would give fullname.
My ultimate goal of this is to list the players, obviously.
In the player_admin/show view, I tried <%= @player.fullname %>, got an
error which said fullname not defined. I also just dumped the player
object using debug(), which didn’t show fullname as an attribute.
I also tried it as a no-param method [i.e., fullname() ], without luck.
After puzzling a while, I came across the notion of helpers, and decided
to try the method in the player_admin_helper:
@player.first_name + " " + @player.last_name
Worked like a charm. I kind of understand, it’s because the show view
was invoked by the player_admin controller, so he has access to the
player_admin_helper, but that won’t help me when I’m off in some other
part of the application.
I don’t understand where I went wrong when just trying to get a similar
method directly in the player object. Is there something funadmentally
wrong with how I’m thinking about Ruby objects, that in the Player model
wasn’t really an appropriate place to try that?