class GalleriesController < SpotControllerBase # some code ... def update if @gallery.update_attributes(params[:gallery]) create_multiple_files(:gallery, @gallery) redirect_to gallery_path(@gallery) else render action: "edit" end end def create @gallery = Gallery.create!(params[:gallery]) create_multiple_files(:gallery, @gallery) redirect_to gallery_path(@gallery) end private def create_multiple_files(parent, record) multiple = params[parent][:file_multiple] multiple.each { |file| record.photos.create! file: file } end end