Rails 4 + HTML: Combine form responses to generate 1 string entry -


i have question on form 15 checkboxes. take items "checked" , combine labels string entered database. rather not make separate db entry every checkbox , selecting individuals on field not important, need record response.

is there easy way combine these , make value entered db?

the following displays right, i'm not sure how submit correct information.

html

<div class="form-inline">     <div class="form-group col-sm-12" style="margin-bottom: 10px">         <div class="field">             <div class="input check_boxes optional remote_issues">                 <label style="display:block; padding-bottom: 1em" class="check_boxes optional">which of following pevent reaching desired weight?</label>                  <% boxes = ["lack of knowledge", "physical limitations", "lack of social support", "hunger", "cravings", "frequent travel", "social events", "no time", "erratic schedule", "finances", "family habits", "stress", "hormonal issues", "medications", "illness", "poor sleep", "health conditions", "age", "slow metabolism", "alcohol", "no exercise", "emotional eating", "food preferences", "other"] %>                  <% boxes.each |box| %>                     <%= render "health_intake", name: box %>                 <% end %>             </div>         </div>     </div> </div> 

_health_intake partial

<span class="checkbox col-xs-3">     <label for="remote_issues_lack_of_knowledge">         <input type="checkbox" value=#{<%= name %>} name="remote[issues][]" class="check_boxes optional" style="margin-right:1em"><%= name %>     </label> </span> 

just join values in controller parameter array:

values = params[:issues].join 

furthermore, add comma or join method can split them later:

values = params[:issues].join(',') 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -