samedi 8 août 2015

Save multiple checkbox rails 4

I have multiple checkbox that I need to save in a mysql DB table. He managed to keep all the form fields except multiples checkboxes. I need to serialize save them, how I can do?

_form.html.erb

        <div class="form-group">
      <%= f.label :news_source, 'Noticias', :class => 'col-lg-2 control-label' %>
      <div class="col-lg-10">
        <%= f.label :news_source, 'El País' %>
        <%= check_box_tag  "news_source[]", '1' %>
        <br>
        <%= f.label :news_source, 'El Observador' %>
        <%= check_box_tag  "news_source[]", '2' %>
        <br>
        <%= f.label :news_source, 'El Espectador' %>
        <%= check_box_tag  "news_source[]", '3' %>
      </div>
    </div>

With Scaffold create my controller

  def create
raise params.inspect
@emission = Emission.new(emission_params)

respond_to do |format|
  if @emission.save
    format.html { redirect_to @emission, notice: 'La emisión fue creada correctamente.' }
    format.json { render :show, status: :created, location: @emission }
  else
    format.html { render :new }
    format.json { render json: @emission.errors, status: :unprocessable_entity }
  end
 end
end




Aucun commentaire:

Enregistrer un commentaire