vendredi 3 juin 2016

create multiple records with checkboxes

I'm trying to create multiple objects, all with the same showing_id and booking_id params but with diffirent seat_ids which depends on selected checkboxes.

Reservedseats model:

class Reservedseat < ActiveRecord::Base
belongs_to :showing
belongs_to :seat
belongs_to :booking
end

the form:

<%= form_for([@booking,@reservedseat]) do |f| %>
<% @reservedseat.booking.showing.screen.seats.order(row: :asc,number::asc).each do |seat| %>
    <%= check_box_tag 'reservedseat[seat_ids][]', seat.id %>
<% end %>
<%= f.hidden_field :booking_id, :value => @booking_id %>
<%= f.hidden_field :showing_id, :value => @booking.showing_id %>

<%= f.submit %>

<% end %>

The idea was to create a booking with name, e-mail etc and pass the params to reservedseats form for selecting multiple seats

create method so far:

def create
@booking = Booking.find(params[:booking_id])
@showing_id = @booking.showing_id
@reservedseat = @booking.reservedseats.build(params[:reservedseat])

unknown attribute 'seat_ids' for Reservedseat.




Aucun commentaire:

Enregistrer un commentaire