我有一个Rails变量,需要将所有日期和时间(send_time)拉入JS数组。我试图使用JS发送时间数组来阻止用户在将来使用这些日期/时间。想想安排一个一小时街区的会议室。两次会议不能同时举行。
我已经检查了JS中的变量。
var taken = <%= @taken.inspect.html_safe %>;
这是检验变量
var taken = [
#<ScheduledRequest _id: 5b7f6b2842195a000400000f, send_time: 2018-08-25 18:00:00 UTC, sent_time: nil, warning_time: 2018-08-25 16:30:00 UTC, actual_send_time: 2018-08-25 16:45:00 UTC, processing: nil, retries: 10, pickup_address: "2209 West Anderson Lane, Boston, MA, USA", dropoff_address: "2209 West Anderson Lane, Boston, MA, USA", round_trip: false, token: nil, pickup_location: [-37.729439, 40.355348], dropoff_location: [-47.729439, 30.355348], notes: "Scheduled: Simple assembly and take away trash.", ip: "XHgw1nn3xIHzfs5t2xzZ/ez0Tj5gg=", notify_email: "", notify_phone: "", user_id: "53f4b008", thingy_type: "Blue Row", thingy_request_id: nil, error: nil, two_hour_warning_sent: nil, identifier: nil, estimated_time: "", thingy_request_log: nil, for_customer_api: false, removed: false, edit_date: "2018-08-25", edit_hours: "01", edit_minutes: "00", edit_ampm: "PM">,
#<ScheduledRequest _id: 5b7f92964029e90004000013, send_time: 2018-08-28 01:00:00 UTC, sent_time: nil, warning_time: 2018-08-27 23:30:00 UTC, actual_send_time: 2018-08-27 23:45:00 UTC, processing: nil, retries: 10, pickup_address: "5501 Spicewood Springs Road, Boston, MA, USA", dropoff_address: "2345 West Anderson Lane, Boston, MA, USA", round_trip: false, token: nil, pickup_location: [-77.771753, 20.384814], dropoff_location: [-57.7322452, 10.356484], notes: "Scheduled:", ip: "XHgwMmB7fk1lRn1Bg8ooqhwM4xQsg=", notify_email: "", notify_phone: "", user_id: "53f4b08", thingy_type: "Blue Row", thingy_request_id: nil, error: nil, two_hour_warning_sent: nil, identifier: nil, estimated_time: "", thingy_request_log: nil, for_customer_api: false, removed: false, edit_date: "2018-08-27", edit_hours: "08", edit_minutes: "00", edit_ampm: "PM">
];
更新:
我去掉了数据,创建了一个新的Ruby数组。
result = []
sr.each do |r|
record = {}
record[:send_time] = r.send_time
record[:ambulance_type] = r.ambulance_type
result << {:ambulance => record}
end
result
var taken = <%= @taken.as_json %>;
现在得到这个(删除敏感信息的数据)。
var taken = [{"thingy"=>{"send_time"=>"2018-08-25T18:00:00.000+00:00", "thingy_type"=>"Row Delivery"}}