Currently, I have a ruby variable accessible by the view called @json
(which contains information I need in JSON format)
However, I want to pass this into a script area such as
<script type="text/javascript" charset="utf-8">
//Want @json to be usable here
</script>
Is there any way to do this?
Assuming the script tag you mentioned is in a html erb view you can just use this:
<script type="text/javascript" charset="utf-8">
var json = <%= @json || 'null' %>;
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With