# Listing of Category error

**URL:** <https://www.ruby-forum.com/t/listing-of-category-error/166384>\
**Category:** Rails\
**Created:** [April 24, 2009, 4:52pm UTC](https://www.ruby-forum.com/t/listing-of-category-error/166384 "2009-04-24T16:52:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![haneef5k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/df788c/32.png) [@haneef5k](https://www.ruby-forum.com/u/haneef5k)\
**Post date:** [April 24, 2009, 4:52pm UTC](https://www.ruby-forum.com/t/listing-of-category-error/166384/1 "2009-04-24T16:52:48Z")

</div>

Im trying to see posts index page, In tat im showing category list, im  
using collect method it show error…

ActiveRecord::StatementInvalid in Posts#index  
Showing app/views/posts/index.html.erb where line #19 raised:

Mysql::Error: Unknown column ‘categories\_posts.category\_id’ in ‘on  
clause’: SELECT `categories`.\* FROM `categories` INNER JOIN  
`categories_posts` ON `categories`.id =  
`categories_posts`.category\_id WHERE ((`categories_posts`.post\_id =  
1))

Extracted source (around line #19):

16:

\<%= post.created\_at.strftime(’%m/%d/%y %I:%m %p’) %\>  
17: \<%= h(post.title) %\>  
18: \<%= h(post.author.display\_name) if post.author %\>  
19: \<%= post.categories.collect {|cat| [cat.name] }.join(",")  
%\>  
20: \<%= h(post.status) %\>  
21: \<%= post.comments\_count %\>

pls help me, im new to RoR…??

---

<div class="post-metadata">

**Author:** ![haneef5k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/df788c/32.png) [@haneef5k](https://www.ruby-forum.com/u/haneef5k)\
**Post date:** [April 24, 2009, 6:13pm UTC](https://www.ruby-forum.com/t/listing-of-category-error/166384/2 "2009-04-24T18:13:12Z")

</div>

You must declare a has\_many :categories in the Post model and a  
belongs\_to :post in the Category model (if the category table has a  
post\_id column, if not keep reading). If you don’t do that, you need  
to create a categories\_posts table with two columns: category\_id and a  
post\_id.

Regards.

Franco C…

---

<div class="post-metadata">

**Author:** ![haneef5k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/df788c/32.png) [@haneef5k](https://www.ruby-forum.com/u/haneef5k)\
**Post date:** [April 24, 2009, 8:21pm UTC](https://www.ruby-forum.com/t/listing-of-category-error/166384/3 "2009-04-24T20:21:02Z")

</div>

Hi,

Im new to Ror, i want to do some userful website can u tell me ur  
advice and wat steps i should to take basically in Ruby on Rails…??  
then im trying to understand tat ( models, controller, action ) it  
confusssed…  
pls help me…

removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![haneef5k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/df788c/32.png) [@haneef5k](https://www.ruby-forum.com/u/haneef5k)\
**Post date:** [April 24, 2009, 8:35pm UTC](https://www.ruby-forum.com/t/listing-of-category-error/166384/4 "2009-04-24T20:35:06Z")

</div>

You can read the Agile Web D. With Rails (http://  
[Pragmatic Bookshelf: By Developers, For Developers](http://www.pragprog.com/titles/rails3)), is a very good book. It explains step  
by step the framework and a very common (but usefull) workflow.

Regards.

Franco C…
