Topic: Need help with 10.3 Michael Hartl's rails 3 toutorial
I am trying to create an index action and view for the User model.
In my users controller the index action is defined as:
def index
@title = "All users"
@users = User.all
end
And in the index.html.erb:
<ul class="users">
<% @users.each do |user| %>
<li>
<%= gravatar_for user, :size => 30 %>
<%= link_to user.name, user %>
</li>
<% end %>
</ul>
When I launch it in the browser I get an undefined method error:
undefined method `email' for nil:NilClass
I know gravatar_for searches its first parabiter for the value of the :email key so I am almost sure this is where it locks up. I tried
firing it up in the rails console.
>> users = User.all
returns an array of all my users
but when I try to itterate through all of them
>> users.each do |u|
>> u.firstName
>> end
it shows no out put and the return is the same as above
I would greatly appriciate any help I am almost done with this toutorial and am really looking forward to learning the more creative aspects of rails.
Hope all is well
Last edited by tystick86 (2011-03-18 03:15:24)