when an user click on my display link, it goes to my display page, a javascript runs after the page load and render the display. something like below:
...
display_data_hash = {}
function display() {
// use display_data_hash here
}
...
is it possible to populate “display_data_hash” in my javascript on the server side? or should i just add tag to my view and populate display_data_hash inside my html. i really don’t want mix javascript with html.
First approach using AJAX
you could retrieve your display_data_hash using AJAX (jQuery here) like:
and in your controller you render a json response like:
Second Approach without AJAX
If you don’t want to fire an AJAX request you could do something like:
In your layout view add a section:
then create a helper method like:
and in your display JavaScript function do: