Here is my problem:
Everything works but I have a display that resembles ["1","2","3"]. I would like 1 2 3. I tried all to_ functions but that does not change ..
Thanks for your time.
model.rb:
validates :check, presence: true
validate :check_must_be_3
private
def checks_must_be_3
if !check != 3
errors[:base] << "You must select exactly 3 checks"
end
end
html:
<%= simple_form_for @answer do |f| %>
<h3>Choose 3 answers</h3>
<ul>
<% (1..5).each do |x| %>
<div class="checkbox">
<label>
<input type="checkbox" name="answer[check][]" id="optionsCheckbox<%= x %>" value="<%= x %>" />
<%= x %>
</label>
</div>
<% end %>
<%= f.button :submit, "Submit", class: "btn btn-primary" %>
<% end %>
controller:
private
def answer_params
params.require(:answer).permit(check:[])
end
answer is a string in db.
Aucun commentaire:
Enregistrer un commentaire