# \[newb\] Controller Help

**URL:** <https://www.ruby-forum.com/t/newb-controller-help/174758>\
**Category:** Rails\
**Created:** [September 1, 2009, 7:27pm UTC](https://www.ruby-forum.com/t/newb-controller-help/174758 "2009-09-01T19:27:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KRKRKR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cab0a1/32.png) [@KRKRKR](https://www.ruby-forum.com/u/KRKRKR)\
**Post date:** [September 1, 2009, 7:27pm UTC](https://www.ruby-forum.com/t/newb-controller-help/174758/1 "2009-09-01T19:27:06Z")

</div>

Hey all been working on my first app that is to help track projects  
and who’s working on them. I want to be able in the project  
controller find employees in the employee controller by project\_id,  
and then list them on my show defenition.

I thought this would work but ofcourse it doesn’t and I can’t find any  
examples in my google searches.

def show  
@project = Project.find(params[:id])  
@employees = Employee.find(params[:project\_id])  
end

If I change the @employees to Employee.find(:all) it will just list  
all employees even if they don’t associate with the project.

any help would be teriffic!

---

<div class="post-metadata">

**Author:** ![KRKRKR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cab0a1/32.png) [@KRKRKR](https://www.ruby-forum.com/u/KRKRKR)\
**Post date:** [September 1, 2009, 8:39pm UTC](https://www.ruby-forum.com/t/newb-controller-help/174758/2 "2009-09-01T20:39:41Z")

</div>

2009/9/1 KR [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Â Â Â Â Â Â Â Â @project = Project.find(params[:id])  
> Â Â Â Â Â Â Â Â @employees = Employee.find(params[:project\_id])  
> end
> 
> If I change the @employees to Employee.find(:all) it will just list  
> all employees even if they don’t associate with the project.

Have a look at the rails guide on active record associations (assuming  
you have already worked through the getting started guide. I imagine  
that you want a has\_and\_belongs\_to\_many association between project  
and employees. Once you set this up then if you have a project in  
@project then @project.employees will give you an array of employees  
working on the project. Similarly if you have an employee then  
@employee.projects will tell you the projects he/she is working on.  
Such is the magic of rails.

Colin
