I just discovered that assigning a ruby object to a javascript variable happens like this: (This is inside the html view)
var markers = <%= @buildings.to_json%>;
Now to access the name attr. of the building do:
markers.building.name
Thats all!