我在 Javascript 中生成了 JSON 格式的记录数组,我想在控制器中创建多个记录。我传递这些数据:
[
{"trip_id":0,"arrival_time":0,"departure_time":0,"stop_id":0,"stop_sequence":0},{"trip_id":1,"arrival_time":1,"departure_time":1,"stop_id":1,"stop_sequence":1},
{"trip_id":2,"arrival_time":2,"departure_time":2,"stop_id":2,"stop_sequence":2},{"trip_id":3,"arrival_time":3,"departure_time":3,"stop_id":3,"stop_sequence":3},
{"trip_id":4,"arrival_time":4,"departure_time":4,"stop_id":4,"stop_sequence":4},{"trip_id":5,"arrival_time":5,"departure_time":5,"stop_id":5,"stop_sequence":5},
{"trip_id":6,"arrival_time":6,"departure_time":6,"stop_id":6,"stop_sequence":6},{"trip_id":7,"arrival_time":7,"departure_time":7,"stop_id":7,"stop_sequence":7},
{"trip_id":8,"arrival_time":8,"departure_time":8,"stop_id":8,"stop_sequence":8},{"trip_id":9,"arrival_time":9,"departure_time":9,"stop_id":9,"stop_sequence":9}
]
我试图或多或少地这样做:
def create
params.each do |stop_time|
StopTime.create stop_time
end
...
,但我不知道如何获取每条记录(如 :id ?或其他?)。
谢谢,
多米尼克