I have two models – Client & Topic, with a HABTM relationship between them.
I am trying to generate a series of checkboxes of the topics, on the Client form partial.
This is what I am doing:
<% Topic.all.each do |topic| %>
<% checked = @client.topics.include?(topic) %>
<%= f.label(:name, topic.name) %> <%= f.check_box @topics, topic.id %>
<% end %>
This is the error I get:
undefined method `merge' for 1:Fixnum
I know one solution is to use check_box_tag, but that forces me to do the record updating of the associations manually.
So I would rather use the form_helper for the checkbox tag. The docs are a bit confusing to me.
How can I get this to work with f.check_box.
Thanks.
For whatever reason, the
formhelper doesn’t work withcheck_box.So, this is the code that works:
According to other answers for similar questions, the helper
f.check_boxis model bound and the value supplied to the checkbox is implicit from the model on the form. The issue is, I can’t figure out how to get the implicit value of the form_helper to produce the correct tag – i.e.client[topic_ids][], so I have had to resort tocheck_box_tag.