# Correct HABTM of use has\_many :through?

**URL:** <https://www.ruby-forum.com/t/correct-habtm-of-use-has-many-through/119617>\
**Category:** Rails\
**Created:** [November 8, 2007, 4:01pm UTC](https://www.ruby-forum.com/t/correct-habtm-of-use-has-many-through/119617 "2007-11-08T16:01:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![remco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@remco](https://www.ruby-forum.com/u/remco)\
**Post date:** [November 8, 2007, 4:01pm UTC](https://www.ruby-forum.com/t/correct-habtm-of-use-has-many-through/119617/1 "2007-11-08T16:01:04Z")

</div>

I have the following setup

class Education \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :users  
end

class User \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :educations  
end

In my user-view-rhtml i have:

```
  <% @user.educations do |education| %>
    <li><%= education.name%></li>

```

This generates empty data…

Question…is my .rhtml wrong or my models??

---

<div class="post-metadata">

**Author:** ![remco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@remco](https://www.ruby-forum.com/u/remco)\
**Post date:** [November 8, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/correct-habtm-of-use-has-many-through/119617/2 "2007-11-08T16:06:24Z")

</div>

On 8 Nov 2007, at 15:01, Remco S. wrote:

> In my user-view-rhtml i have:
> 
> ```
> <% @user.educations do |education| %>
> <li><%= education.name%></li>
> 
> ```

That seems ok.

Fred

---

<div class="post-metadata">

**Author:** ![remco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@remco](https://www.ruby-forum.com/u/remco)\
**Post date:** [November 8, 2007, 4:09pm UTC](https://www.ruby-forum.com/t/correct-habtm-of-use-has-many-through/119617/3 "2007-11-08T16:09:11Z")

</div>

Frederick C. wrote:

> On 8 Nov 2007, at 15:01, Remco S. wrote:
> 
> > In my user-view-rhtml i have:
> > 
> > ```
> > <% @user.educations do |education| %>
> > <li><%= education.name%></li>
> > 
> > ```
> 
> That seems ok.
> 
> Fred

yep…i thought so

There is a join table education\_user involved…that is the problem…i  
guess…

---

<div class="post-metadata">

**Author:** ![remco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@remco](https://www.ruby-forum.com/u/remco)\
**Post date:** [November 15, 2007, 9:25am UTC](https://www.ruby-forum.com/t/correct-habtm-of-use-has-many-through/119617/4 "2007-11-15T09:25:43Z")

</div>

I think the problems is in the iteration in your view, it should be:  
\<% @user.educations.each do |education| %\>

- \<%= education.name%\>

CU

Geoffroy G.

Joan Gu wrote:

> > 
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
View this message in context:  
[http://www.nabble.com/Correct-HABTM-of-use-has\_many-%3Athrough--tf4771440.html#a13762790](http://www.nabble.com/Correct-HABTM-of-use-has_many-%3Athrough--tf4771440.html#a13762790)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![remco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@remco](https://www.ruby-forum.com/u/remco)\
**Post date:** [November 15, 2007, 10:28am UTC](https://www.ruby-forum.com/t/correct-habtm-of-use-has-many-through/119617/5 "2007-11-15T10:28:15Z")

</div>

webapart wrote:

> I think the problems is in the iteration in your view, it should be:  
> \<% @user.educations.each do |education| %\>
> 
> - \<%= education.name%\>
> 
> CU
> 
> Geoffroy G.
> 
> Joan Gu wrote:
> 
> > > 
> > 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> –  
> View this message in context:  
> [http://www.nabble.com/Correct-HABTM-of-use-has\_many-%3Athrough--tf4771440.html#a13762790](http://www.nabble.com/Correct-HABTM-of-use-has_many-%3Athrough--tf4771440.html#a13762790)  
> Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

Geoffroy

It is working now!!!..

Thanks!!!

remco
