###前提・実現したいこと
form_forで1週間分の一括登録を行いたい。
現状最終日のデータしか、createに渡らない。
###該当のソースコード
#app/view/reservations/new.html.slim = form_for @reservations, :html => { class: "form-horizontal"} do |f| - 7.times do td = f.hidden_field :date , :value => @base_date = f.label :count_max , "座席数:" = f.number_field :count_max br = f.label :price , "通常価格:" = f.number_field :price br = f.label :discount_price , "割引価格:" = f.number_field :discount_price - @base_date.tomorrow = f.submit "登録", class: "btn btn-primary"
#app/controller/reservations_controller.rb def new require 'date' #binding.pry @plan = Plan.find_by(id: params[:plan_id]) if current_owner.id == @plan.owner_id #オーナーが所有するPlanならば @reservations = @plan.reservations.build #1週間分を用意 7.times{ @reservations } @today = Date.current #登録は翌日から @base_date = @today.tomorrow #binding.pry else #オーナーが所有するPlanじゃない時 redirect_to owner_path, flash: { error: @pre_regist.errors.full_messages } end end def create @reservation = Reservation.new(reservation_params) binding.pry end private def reservation_params params.require(:reservations).permit(:date, :count_max, :coutnt,:price,:discount_price) end
どのようにすれば、1週間分のデータをcreateに渡せるか、ご存知の方いらっしゃいましたら、ご教授いただけませんでしょうか。
よろしくお願いいたします。
あなたの回答
tips
プレビュー