1

I am trying to interface with the YouTube player API. This works fine. However, the API lets you define callbacks that are fired whenever, for instance, the video has finished playing. I would like to call a ModelController action at that time. How can I access actions on my ModelController from within native JS? Opal.Volt.??? ?

[question copied from gitter]

Ryan
  • 956
  • 7
  • 8

1 Answers1

1

on the accessing the model controller. What you want to do is set the callback up from inside of the controller. In opal you can use a proc (not a block) as a callback (since it can be used in place of a JS function) Then inside of the proc, call whatever you want on the ModelController. You can also convert a method into

module Main
  class MainController < Volt::ModelController
    def index
      callback = proc {|*args| some_method(*args) }
      `youtube.someHandler(callback);`
    end
  end
end
Ryan
  • 956
  • 7
  • 8