我對帶有15個複選框的表單有疑問。我想採取所有「檢查」的項目,並將標籤結合到輸入到我的數據庫的字符串。我寧願不爲每個複選框都創建一個單獨的數據庫條目,並且在此字段上選擇個人並不重要,我只需要記錄響應。Rails 4 + HTML:結合表單響應以生成1個字符串條目
有沒有簡單的方法來結合這些,並使價值輸入數據庫?
以下顯示正確,但我不確定如何實際提交正確的信息。
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 the following pevent you from reaching your 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 do |box| %>
<%= render "health_intake", name: box %>
<% end %>
</div>
</div>
</div>
</div>
_health_intake部分
<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>