Ruby on Rails. Creat multiple records with one form and an array -


i have form create 'gigs, works. i'm trying add feature allow users create same 'gig' multiple times, different dates. (all other attributes remain same)

heres have far: (please note, have tried ton of different things, latest iteration, cannot remember past versions didn't work)

_form.html.erb

<div class="multiple-gigs-cont">   <% @tokens = current_user.tokens.count %>   <% @tokens.times %>     <%= datetime_field_tag :reo_datetime, "", :name => "reo[][datetime]" %>   <% end %> </div> 

users have tokens, here date field gets repeated same amount of times amount of tokens user has.

gigs_controller.rb

def create       @gig_dates = params[:reo]         @gig_dates.each |datetime|       @gig = gig.new gig_params       @gig.date = datetime.to_s       @genres = genre.where(:id => params[:choose_genres])       @gig.genres << @genres         end      if @gig.save           bla bla bla bla etc..      else           render 'new'      end    end 

i want create new record each item in datetime array.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -