How to embed Ruby in JavaScript (Rails + .html.erb file)

后端 未结 4 1051

I have a .html.erb file, with some javascript in it. I would like to do something like this:

var stuff = \'
<%= @ruby_var.title %>
\'
4条回答
  •  天命终不由人
    2021-02-05 07:34

    You can use the javascript_tag function to include Javascript in a .html.erb file.

    Example:

    javascript_tag "alert('This is a test')"
    

    in your foo.html.erb will return

    
    

    to the browser.

提交回复
热议问题