How to print a variable defined in Javascript in Opal-rails

How can I access a variable in opal-ruby code that was previously defined in javascript? For example, in the following code, how to fix an opal file.

index.html.erb

... <script> var test = "hi" </script> ... 

index.js.opal

 Document.ready? do puts test end 
+4
source share
1 answer

Opal allows you to use backticks to output any raw JavaScript that you do not want Opal to interpret, so this will result in the output of a test string containing "hi":

 Document.ready? do puts `test` end 
+2
source

Source: https://habr.com/ru/post/1445341/


All Articles