I have a form that, among other things, contains about 20 different flags. For instance:
<%= form_for @inventory do |f| %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
...
<p>
<%= f.check_box :apple %><%= f.label :apple %><br />
<%= f.check_box :banana %><%= f.label :banana %><br />
<%= f.check_box :orange %><%= f.label :orange %>
...
</p>
...
<% end %>
What I want to do is take the value of the selected checkbox, separate them with a comma and save in a column in db. Therefore, if the apple and orange check box is checked, it is saved as:
@ inventory.fruit = "apple, orange"
how to do it?
source
share