When i create a new post (passengerride), it is successfully storing multiple value in database. But, when i try to edit the post (passengerride), the checkboxes are getting unchecked.
This is my form:
apps/views/passengerrides/_form.html.erb:
<%= form_for @passengerride do |f| %>
......
<div class="form-group ">
<div class="control-label col-sm-2 requiredField">
<%= f.label :okwithgender, 'Driver should be:' %>
<span class="asteriskField">*</span>
</div>
<div class="col-sm-8">
<div class=" ">
<div class="checkbox">
<label class="checkbox"><input id="okwithgender" type="checkbox" value="Male" name="passengerride[okwithgender][]">Male</label>
</div>
<div class="checkbox">
<label class="checkbox"><input id="okwithgender" type="checkbox" value="Female" name="passengerride[okwithgender][]">Female</label>
</div>
<div class="checkbox">
<label class="checkbox"><input id="okwithgender" type="checkbox" value="Other" name="passengerride[okwithgender][]">Other</label>
</div>
<div class="checkbox">
<label class="checkbox"><input id="okwithgender" type="checkbox" value="Any Gender" name="passengerride[okwithgender][]">Any Gender</label>
</div>
</div>
</div>
</div>
....
<% end %>
app/controllers/passengerrides_controllers:
def passengerride_params
params[:passengerride][:okwithgender] = params[:passengerride][:okwithgender].join(', ')
params.require(:passengerride).permit(:origin, :destination ... :okwithgender)
end
I guess using this <%= f.check_box ... %>
will solve the problem, but i'm not sure how to write something equivalent to <input id="okwithgender" type="checkbox" value="Male" name="passengerride[okwithgender][]">
Aucun commentaire:
Enregistrer un commentaire