title: RoR - undefined local variable or method `user'
body: <p>I am fairly still new to ruby on rails and don't fully understand why I am getting the following error:</p>
  
  <pre><code> undefined local variable or method `user' for #&lt;StatisticsController:0xb9a20d0&gt;
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>class StatisticsController &lt; ApplicationController
    before_filter :authenticate, :only =&gt; [:index]
  
    def index
  
      @title = "Statistics"
      @projects = Project.all 
      @data = []
  
  
      Project.all.each do |project|
        projdata = { 'name' =&gt; project.project_name.to_s,
                    'values' =&gt; [] }
  
        ['Pre-Sales','Project','Fault Fixing','Support' ].each do |taskname|
  
            record = Effort.sum( :hours,
            :joins =&gt; {:project_task =&gt; {:efforts =&gt; :user}},
            :conditions =&gt; { "project_tasks.efforts.user_id" =&gt; user.id,                             
                "project_tasks.project_id" =&gt; project.id,
             "project_tasks.task_name" =&gt; taskname } )
  
          projdata[ 'values' ].push( record )
        end
  
        @data.push( projdata )
      end
    end
  end 
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <pre><code>class StatisticsController &lt; ApplicationController
    before_filter :authenticate, :only =&gt; [:index]
  
    def index
  
      @title = "Statistics"
      @projects = Project.all 
      @data = []
  
  
       User.all.each do |user|
        projdata = { 'name' =&gt; user.user_id.to_s,
                    'values' =&gt; [] }
  
        ['Pre-Sales','Project','Fault Fixing','Support' ].each do |taskname|
            user = User.all 
            record = Effort.sum( :hours,
            :joins =&gt; {:project_task =&gt; {:efforts =&gt; :user}},
            :conditions =&gt; { "project_tasks.efforts.user_id" =&gt; user.id,                             
                             "project_tasks.project_id" =&gt; project.id,
                             "project_tasks.task_name" =&gt; taskname } )
  
          projdata[ 'values'].push( record )
        end
  
        @data.push( projdata )
      end
    end
  end 
  </code></pre>