rails

Pass Data from Rails to JavaScript

Shou Arisaka
1 min read
Oct 18, 2025

A method to execute Ruby erb within Javascript code when using Javascript in .html.erb files.

<%= javascript_tag do %>
  window.your_object = <%= raw @your_object.to_json %>;
<% end %>

Share this article

Shou Arisaka Oct 18, 2025

๐Ÿ”— Copy Links