You could do it by looping through the JSON hash you receive, saving each record as you go:
def create
for visit in params[:visit] do
new_visit = Visit.new(user_params)
new_visit.save
end
redirect_to visits_path
end
private
def user_params
params.require(:visit).permit(:room_id, :date) # => we'll need to fix this
end
The bottom line is that just because you're meant to send data in a specific way, doesn't mean you can't do it other ways. You can loop through passed params, allowing you to call the save
method on each [:visit]
param you pass