I want to get possibility to select several Categories for one Post with multiple select.
I have next models: Post, Category and PostCategory.
class Post < ActiveRecord::Base
has_many :post_categories
has_many :categories, :through => :post_categories
end
class Category < ActiveRecord::Base
has_many :post_categories
has_many :posts, :through => :post_categories
end
class PostCategory < ActiveRecord::Base
has_one :post
has_one :category
belongs_to :post # foreign key - post_id
belongs_to :category # foreign key - category_id
end
In my controller I have something like @post = Post.new . I've created some categories.
And in view I have:
<%= form_for @post do |f| %>
<%= f.text_field :title %>
<%= f.select :categories, :multiple => true %>
<%= f.submit %>
<% end %>
And... where is my categories? I have only "multiple" in select options. I think it's something wrong with my form.