0

I have two models Post and PostCategory both of which have has_and_belongs_to_many relationships.

I have created manually three post_categories: news, don't miss and announcements.

When i create a new post i want to be able to choose in which categories it belongs to via a select with multiple="true".

Attention: I don't want to create a new category on post creation but to attach one or more categories to this post!

dax
  • 10,779
  • 8
  • 51
  • 86

1 Answers1

0

You can do smth like:

form.select :category_ids, PostCategory.all.map{ |pc| [pc.name_or_smth_else, pc.id] }, {}, {:multiple => true}

Take a look at "4.4.1.8 collection_singular_ids" section of the guide

Babur Ussenakunov
  • 1,995
  • 2
  • 16
  • 16