Using Ruby variable in Javascript (In App View)
javascript, ruby, ruby-on-rails
Solution
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>
Problem
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?