You should consider making API endpoints(a controller action) that returns a JSON to an AJAX request to it. This would be worth doing, if the data you are fetching is dynamic.

If you think that the above would be an overkill, try the below described method instead.

Assuming you have set @directory (containing a ruby hash) in the action rendering the view you referred to, you can do the following :

<script type="text/javascript">
  var directory_tree = <%= raw(@directory.to_json) %>

Related Query