title: Listing users in rails +template error
body: <p>I am starting my learning process by first listing all the users.</p>
  
  <p>First I had added an action in the controller as </p>
  
  <pre><code>def list_users
    @users=User.find(:all)
  end
  </code></pre>
  
  <p>And in the View <code>users/list_users.html.erb</code> I have added the line</p>
  
  <p><code>list_users.html.erb</code>:</p>
  
  <pre><code>&lt;%= Time.now %&gt;
  
  &lt;% @users.each do |user| %&gt;
    &lt;%= user.firstname %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>And for routing I have added the routes as</p>
  
  <pre><code>map.list_users '/list_users', :controller =&gt; 'users', :action =&gt; 'list_users'
  </code></pre>
  
  <p>That's it .. when I run my app , it's showing me the error as</p>
  
  <pre><code>     Development mode eh? Here is the error - #&lt;ActionView::TemplateError: 
       ActionView::TemplateError (You have a nil object when you didn't expect it!
        You might have expected an instance of Array.
        The error occurred while evaluating nil.each) on line #7 of app/views/users/list_users.html.erb:
  </code></pre>
  
  <p>Why so?</p>
  
  <hr>
  
  <p>Solution:</p>
  
  <p>I myself find that the controller action is under protected, that's why it showed me the error.</p>