Unfortunately, you can’t directly convert a Ruby variable into a Js variable because they run on different sides of the application (Ruby on the server-side and Js on the client-side).
But you can pass the variable from Ruby to Js via HTML tags. Here’s how:
<script type="text/javascript">
var file_dir = "<%= @modelPath %>";
</script>
In your Ruby file, make sure to set @modelPath before rendering the view.
In your Js function get_path(), you can directly use file_dir. It now holds the path data from Ruby.