0

我有兩個模型PostPostCategory兩者都有has_and_belongs_to_many關係。附加模型has_and_belongs_to_many關係在軌道上

我已經手動創建了三個post_categoriesnews,don't missannouncements

當我創建一個新的post我希望能夠選擇在categoriesbelongs to通過selectmultiple="true"

注意:我不想對post創建創建一個新的category但要附加一個或多個categories這個post

回答

0

你可以像水木清華:

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

guide

+0

致謝 「4.4.1.8 collection_singular_ids」 部分看一看!解決了我的問題,並向我清楚:) – jimzarkadas