Rails 3: Multiple Select with has_many through associations

后端 未结 5 2089
温柔的废话
温柔的废话 2020-11-27 11:24

I want to get possibility to select several Categories for one Post with multiple select.

I have next models: Post, Category and PostCategory.

class          


        
5条回答
  •  执念已碎
    2020-11-27 11:45

    Tigraine almost had it, but you need to specify an additional empty hash:

    <%= f.select :category_id, Category.all.collect {|x| [x.name, x.id]}, {}, :multiple => true %>

提交回复
热议问题