Reputation: 56709
I have a javascript function that takes data from Rails and presents it.
The format it needs:
[
{
title: 'All Day Event',
start: new Date(y, m, 1)
},
{
title: 'Long Event',
start: new Date(y, m, d-5),
end: new Date(y, m, d-2)
}
]
I'm trying to present this data directly from Rails:
<%= raw @bookings.as_json( only: [:title, :start, :end] ).collect{|o| o["booking"]} %>
This is pretty close, producing:
[{"end"=>nil, "start"=>nil, "title"=>...}, {...}, {...}]
All I have left to do now is change each =>
into :
.
Upvotes: 1
Views: 82
Reputation: 6464
Try using to_json
instead of as_json
. as_json
is old syntax and hence may not work.
Upvotes: 1