Timeline for How do I make a ruby variable accessible to a javascript file?
Current License: CC BY-SA 3.0
3 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 8, 2013 at 1:02 | comment | added | Lai Yu-Hsuan |
I mean to write <div id="foo" data-lat="<%= @user.lat %>"></div> in your .html.erb file. JavaScript can access HTML attributes, so them can be used to pass data between Ruby and JavaScript.
|
|
| May 8, 2013 at 0:50 | comment | added | CHarris | Do you mean just define <div id="foo" data-lat="<%= @user.lat %>"></div> in my js file, then map_latitude = $("#foo").data("lat");, and then use the variable map_latitude in my google maps function? | |
| May 8, 2013 at 0:43 | history | answered | Lai Yu-Hsuan | CC BY-SA 3.0 |