# Need help with join / edit

**URL:** <https://www.ruby-forum.com/t/need-help-with-join-edit/145797>\
**Category:** Rails\
**Created:** [August 14, 2008, 12:33am UTC](https://www.ruby-forum.com/t/need-help-with-join-edit/145797 "2008-08-14T00:33:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [August 14, 2008, 12:33am UTC](https://www.ruby-forum.com/t/need-help-with-join-edit/145797/1 "2008-08-14T00:33:42Z")

</div>

Hi i have a issue here:  
Model: COMPANY  
Model: USER  
JOIN-MODEL: user\_company

in the index view of the user i would like to have a second row per each  
user to insert a index / vire partial from the User-Company-Join  
relation:

user/index:

# Listing Users

\<% for u in @users %\>

 \<% end %\>

| Firstname | Lastname | Username |
| --- | --- | --- |
| \<%=h u.firstname + u.id.to\_s %\> | \<%=h u.lastname %\> | \<%=h u.username %\> | \<%= link\_to 'Show', u %\> |
| \<%=h render :partial =\>'user\_companies/edit', :local =\> @users %\> |

  

* * *

## user\_company controller: def edit @user\_company = UserCompany.find(params[:id]) end

user\_companies / edit :

# Editing user\_division

\<% form\_for(@user\_company) do |f| %\>  
\<%= f.error\_messages %\>

Record ID:  
 \<%= @user\_comp.id %\>

\<%= f.submit "Update" %\>

\<% end %\> --------------------------------------------------- its givin me : Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object\_id all the time... please guys give me a hint...thx

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [August 14, 2008, 12:37am UTC](https://www.ruby-forum.com/t/need-help-with-join-edit/145797/2 "2008-08-14T00:37:42Z")

</div>

Just at a glance it looks like you should change @user\_comp to  
@user\_company in user\_companies/edit.

And as a tip if you don’t have any additional fields to keep track of  
in your user\_company model, you should use a has\_and\_belongs\_to\_many  
relationship.

-J.

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [August 14, 2008, 3:11pm UTC](https://www.ruby-forum.com/t/need-help-with-join-edit/145797/3 "2008-08-14T15:11:00Z")

</div>

hi, mh ur right, but still it complains about the variable im using in  
the partial…  
partial:

\<% form\_for(@users.companies) do |f| %\>

> >

undefined method `companies’ for #Array:0xb6c106a4

> > what i wanna achivee is the join table between user and company. the rb’s are ok.

thx tom
