Rieles: guardar valores de casilla de verificación

Just trying to save the values of 4 checkboxes into a column named reminders a mi Boletos Model.

But, either the values aren't being saved, or when I go back to edit this "Ticket" its not ale to pull the data from the db and display the true / false vaules correctly.

¿Algún consejo?


<%= form_for(@ticket) do |f| %>    

  <% [ 'S.T.A.R.T', 'E.N.D.E.D', 'URGENT' , 'Repeat Request' ].each do |reminder| %>
  <br><%= check_box_tag 'reminders', reminder, (params[:reminders] || {}).include (reminder) %>
  <%= reminder.humanize %>
  <% end %>

<div class="actions">
  <%= f.submit %>

<% end %>

preguntado el 05 de mayo de 13 a las 18:05

1 Respuestas

Rather than using check_box_tag the way you are, change it to use your form builder object provided by form_for. It'll ensure that the name of the checkbox is correct which is your problem (I think).

Because you're not using it, the checkbox is probably taking on a different name to what rails is expecting to see, so when you submit the form, the param name won't be associated with your record and thus won't be changed. Try using

<%= f.check_box_tag :reminder %>

Rails will automatically handle whether or not it is ticked when the page loads :)

contestado el 05 de mayo de 13 a las 23:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.