Menu
  • HOME
  • TAGS

Cannot use Ruby Math library with Opal

javascript,ruby,opalrb,opal

The Math module is in Opal's stdlib and isn't included in the default runtime (as far as I can tell). Depending on your deployment context, it might be easiest to build the Math module (Opal::Builder.build('math')) into a file. For your specific example, though, you can just use the JS PI...

Seed Random in Opal

random,opalrb

Not at the moment. There's an open PR that should fix this, but it's kinda stalled https://github.com/opal/opal/pull/657 Would need someone to pick up and complete the work that was started. ...

How to make pages with a “template” controller and view in VoltRb

html,ruby,pagination,opalrb,voltrb

You could for example use the following routes: client '/books', controller: 'books', action: 'index' client '/books/{{ genre }}/{{ title }}', controller: 'books', action: 'template' This will route both requests to the books controller. And it will make the genre and title available via the params collection in the template controller...

rails-opal and opal ujs on remote: true

ruby,opalrb

If someone will face that issue: you should render js file with .opal extension like remote_reply.js.opal and that will do.

Opal.rb anonymous function in native object

ruby,opalrb

I'm guessing you want to pass a ruby method as a callback to a javascript function, you could try something like this: x = { bar: method(:foo).to_proc } x.to_n But bear in mind that this might not work as intended for class methods ( the context might change on javascript)...

Event Complete Callbacks with Opal-jQuery

opalrb,opal

You could use a Promise which is a technique to manage long-term asynchronous events and avoid callback-hell. In regular Opal you would do for example: HTTP.get("url") do |response| puts "got response" end With promises, this becomes: HTTP.get("url").then do |response| puts "got response" end The difference lies in the then which...

Appending an element to a page in VoltRb

html,ruby,opalrb,voltrb

Ok, so the problem is that the code you have is being loaded as soon as the compiled .js file loads. You need to run the code once the DOM is ready. The easy way to do this in volt is to run it on a {action}_ready method: module Main...

How shall I migrate to opal 0.7.0.beta

opalrb

Something like the following should work: require 'opal' task :build do env = Sprockets::Environment.new Opal.append_path '.' Opal.use_gem 'vector2d' Opal.paths.each { |p| env.append_path(p) } File.open(ZUPFNOTER_JS, 'w+') { |out| out << env['application.js'].to_s } # … end I also suggest to use the same sprockets environment to build SCSS too as it should...

How to access a page's URL in VoltRb

ruby,url,opalrb,voltrb

If you are using bindings in your URL, for example client '/examples/{{ category }}/{{ example }}', controller: 'examples', action: 'template' you can access those in the controller via the params collection: params._category params._example In other cases you URL should be static anyway....

How writing text onto specific place [Opal]

javascript,opalrb

Ok, so based on your sample code, you just need to make Opal.main() return a string def main # logic return str end But I think that what you really want is use opal-jquery or opal-browser, I don't have much experience with the later, so here's a simple example of...

Opal rb eval method throws 'undefined method'

ruby,opalrb

Kernel#eval is defined in opal-parser as it needs to be able to parse Ruby into JS in the browser, so you need to require "opal-parser" first.

OpalRB: Using functions as parameters

javascript,ruby,opalrb

The following should work fine: require 'native' @Meteor = Native(`Meteor`) @Meteor.startup -> { puts 'Go' } Note that using Native you pass a lambda instead of a block...