title: ActiveRecords Associations: undefined method for nil:NilClass
body: <p>first of all this is my first Rails application, so please be indulgent... I read the Rails Guides for associations in <a href="http://guides.rubyonrails.org/association_basics.html" rel="nofollow">http://guides.rubyonrails.org/association_basics.html</a> and then started to code my own project. My problem is that I can't do stuff like @project.user.email because @project.user seems to be nil all the time. This happen for all objects. @user.role.name also throws "undefined method for nil:NilClass"; I'm sure I'm doing wrong someting with the models definitions but I don't understand what it is. I appreciate your help. Thanks.</p>
  
  <pre><code>   class Role &lt; ActiveRecord::Base
        has_many :users
        attr_accessible :name
     end
  
     class User &lt; ActiveRecord::Base
        belongs_to :role
        has_many :projects
        attr_accessible :email, :password, :password_confirmation, :role_id, :role  
     end
  
     class Project &lt; ActiveRecord::Base
        belongs_to :user
        belongs_to :project_type
        attr_accessible :id, :project_type_id, :title, :description  
     end
  
     class Project_Type &lt; ActiveRecord::Base
        has_many :projects
        attr_accessible :name
     end
  </code></pre>
  
  <p>An example would be for instance the index view for projects where I do (HAML):</p>
  
  <pre><code>   %td= proyecto.user.email
  </code></pre>
  
  <p>which wouldn't work. However, </p>
  
  <pre><code>   %td= proyecto.user_id
  </code></pre>
  
  <p>does work fine.</p>