08 May 2012
- Include the Google Maps API
- Define the
- Call the
onload(one the page has finished loading)
Here’s a before and after for the Coffeescript/jQuery makeover:
Variables scoped locally by default, curly braces made redundant, semi-colons unecessary, readability increased and number of lines reduced. Of course, this only scratches the surface of what Coffeescript offers. Notice also the use of jQuery to select the ‘map_canvas’ div, remembering that the selector returns an array and we want the actual DOM element.
onload to the
Including the Maps API
As I mentioned it above, it’d be rude not to elaborate - here’s a quick Rails example of how it can be done. We don’t want to simply place a
content_for which is then rendered in your layout with use of the yield method. Hopefully this makes it clear:
:js symbol can be anything, it’s simply an identifier but it helps to keep it somewhat generic so the yield can be used by other views.