ruby - Rails: has_many, through not showing in view/index -


i'm writing simple time tracking app user has_many clients , client has_many projects.

i want user able view list of projects (for clients). implement this, i've set has_many, through relationship between users , projects.

but reason can't projects show in index view. there's simple reason i'm not noticing, apologies upfront if that's case.

here's relevant code.

project index controller:

def index     @projects = current_user.projects.paginate(:page => params[:page], :per_page => 6) end  

project model:

class project < activerecord::base   belongs_to :client    validates :name, presence: true, length: { maximum: 30 }   validates :fee, presence: true, numericality: { only_integer: true,    greater_than_or_equal_to: 0, less_than_or_equal_to: 100000 }   validates :client_id, presence: true  end 

client model:

class client < activerecord::base     belongs_to :user     has_many :projects, dependent: :destroy      validates :user_id, presence: true     validates :name, presence: true, length: { maximum: 30 }     validate :user_id_is_valid      private       def user_id_is_valid         errors.add(:user_id, "is invalid") unless user.exists?(self.user_id)     end  end  

relevant part of user model:

class user < activerecord::base   has_many :clients, dependent: :destroy   has_many :projects, through: :clients 

index.html.erb:

<div id="projects-list">     <% if current_user.projects.any? %>         <h3>projects</h3>         <ul class="project-list">             <% render @projects %>         </ul>         <%= will_paginate @projects %>     <% end %> </div> 

_project.html.erb:

<li>     <%= link_to "#{project.name}", '#' %> </li> 

it should be:

<%= render @projects %> 

not:

<% render @projects %> 

Comments