# Content\_columns returns nothing

**URL:** <https://www.ruby-forum.com/t/content-columns-returns-nothing/129256>\
**Category:** Rails\
**Created:** [February 15, 2008, 8:24pm UTC](https://www.ruby-forum.com/t/content-columns-returns-nothing/129256 "2008-02-15T20:24:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nahabed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b77776/32.png) [@nahabed](https://www.ruby-forum.com/u/nahabed)\
**Post date:** [February 15, 2008, 8:24pm UTC](https://www.ruby-forum.com/t/content-columns-returns-nothing/129256/1 "2008-02-15T20:24:44Z")

</div>

I have a model “wanted\_offers” that’s defined as a “belongs\_to” with  
another model. All that wanted\_offers has is two foreign keys in two  
columns.

I’ve implemented a show method and passing in the id of the  
wanted\_offer that the user clicks on.

The method is not displaying anything. The “\<% for column in  
WantedOffer.content\_columns %\>” isn’t executing.

When I look at the database, it looks as expected with two rows.  
mysql\> select \* from wanted\_offers;  
±—±--------±--------+  
| id | user\_id | book\_id |  
±—±--------±--------+  
| 2 | 5 | 2 |  
| 3 | 5 | 3 |  
±—±--------±--------+  
2 rows in set (0.00 sec)

column\_names seems to return the right results

> > WantedOffer.column\_names  
> > =\> [“id”, “user\_id”, “book\_id”]

However, content\_columns is returning nothing ☹

> > WantedOffer.content\_columns  
> > =\> []

Any ideas why?

---

<div class="post-metadata">

**Author:** ![nahabed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b77776/32.png) [@nahabed](https://www.ruby-forum.com/u/nahabed)\
**Post date:** [February 15, 2008, 10:28pm UTC](https://www.ruby-forum.com/t/content-columns-returns-nothing/129256/2 "2008-02-15T22:28:37Z")

</div>

Me again… I suppose Ruby is doing the RIGHT thing by returning null  
on content\_columns call since the child doesn’t have any content per  
se - it just holds two foreign keys. So maybe I can restate my Q…

How do I get at a parent of WantedOffer in this type of call? \<% for  
column in WantedOffer.content\_columns %\>

---

<div class="post-metadata">

**Author:** ![nahabed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b77776/32.png) [@nahabed](https://www.ruby-forum.com/u/nahabed)\
**Post date:** [February 16, 2008, 6:52pm UTC](https://www.ruby-forum.com/t/content-columns-returns-nothing/129256/3 "2008-02-16T18:52:20Z")

</div>

nahabed,

I’m not sure that rendering for .content\_columns is something you’d  
want to do in production. It may get things out quickly for  
development but I’d suspect you will quickly want more control that  
what that will allow.

As to your real question… I’m making an assumption from the keys in  
your wanted\_offers db that you might be able to build your classes  
like this:

class User  
has\_many :wanted\_offers

has\_many :wanted\_books :through=\>:wanted\_offers, :class\_name=\>‘Book’,  
…  
end

(You should mirror this in Book)

With that in place you should be able to do something like this:

@user.wanted\_books.each do |book|  
book.content\_columns.each do |book\_column|  
…whatever it is you were trying to do…  
end  
end

HTH,  
AndyV
