what else to do to establish many-to-many associations in Ruby on Rails? thanks!
Posted
by john
on Stack Overflow
See other posts from Stack Overflow
or by john
Published on 2010-06-10T01:09:51Z
Indexed on
2010/06/10
1:42 UTC
Read the original article
Hit count: 198
ruby-on-rails
|many-to-many
Hi, I have two classes and I want to establish a many-to-many assications, here is the code:
class Category < ActiveRecord::Base
has_and_belongs_to_many :events
has_and_belongs_to_many :tips
end
class Tip < ActiveRecord::Base
has_and_belongs_to_many :categories
However, I kept getting the following errors and I would appreciate it if some one could educate me what is going wrong:
PGError: ERROR: relation "categories_tips" does not exist
: SELECT "categories".id FROM "categories" INNER JOIN "categories_tips" ON "categories".id = "categories_tips".category_id WHERE ("categories_tips".tip_id = NULL )
the viewer part:
4: <%= text_field :tip, :title %></label></p>
5:
6: <p><label>Categories<br/>
7: <%= select_tag('categories[]', options_for_select(Category.find(:all).collect {|c| [c.name, c.id] }, @tip.category_ids), :multiple => true ) %></label></p>
8:
9: <p><label>Location<br/>
10: <%= text_field_with_auto_complete :tip, :abstract %></label></p>
© Stack Overflow or respective owner