collection_check_boxes with has_many through: association Rails 4

213 views
Skip to first unread message

Cameron Craig

unread,
Apr 6, 2014, 6:46:27 PM4/6/14
to rubyonra...@googlegroups.com
I am trying to list all the categories a user can be interested in with check boxes so that a user can submit these interests through my join table.

collection_radio_buttons works with a simple has_many, belongs_to association:

<%= collection_radio_buttons(:listing, :category_id, Category.all, :id, :name do |b| %>
     <%= b.label { b.radio_button} %>
     <%= b.text %>
<% end %>

I am not sure how to go about this so that I can get all the categories from it's model and write the corresponding id's to the join table?

James Davis, PhD

unread,
Apr 8, 2014, 7:41:39 AM4/8/14
to rubyonra...@googlegroups.com
http://railscasts.com/episodes/17-habtm-checkboxes-revised

Here is a railscast where Ryan Bates uses HABTM to accomplish what you ask. It shouldn't be to difficult to adopt his logic for 'has many through'.

Reply all
Reply to author
Forward
0 new messages