opal / opal-rails

Bringing Ruby to Rails · Rails bindings for Opal
http://opalrb.com/#getting-started-rails
488 stars 65 forks source link

How to execute the ruby code in browser ? #116

Closed Hareramrai closed 4 years ago

Hareramrai commented 4 years ago

I was trying to use the compile method but it's not working.

I was trying the code from below git repo & it was working in that application but not working with opal-rails.

https://github.com/ruby/TryRuby/blob/master/source/javascripts/try_ruby.js.rb#L248

Document.ready? do
  editor = Element.find("#editor")

  puts editor

  Element.find("#btn_run").on(:click)   { do_run }

  def do_run
    editor = Element.find("#editor")
    puts editor.value

    eval_code Opal.compile(editor.value, source_map_enabled: false)
  end
end

This is the error, I am getting in the browser.

kernel:536 Uncaught constructor {name: "compile", message: "undefined method `compile' for Opal", args: Array(2), stack: "compile: undefined method `compile' for Opal↵    a…2910799d5a1ca4cdef24042b571d8a.js?body=1:4992:28)"}

Please help me with this issue.

Hareramrai commented 4 years ago

I got it working after importing require "opal-parser".