Ruby functions inside javascript (allowing AJAX requests to kinda work) #12

jphastings opened this Issue Aug 30, 2010 · 1 comment


None yet
1 participant

I'm trying to complete unit tests on some javascript I've written using RightJS and their AJAX function Xhr.load.

As far as I can tell envjs, Johnson (and hence Harmony) dont' yet support AJAX calls, so this won't work exactly as planned. However I should be able to hack around this if I can do something like this:

class HarmonyHelpers
  def initialize(harmony_page)
    @harmony = harmony_page

  def xhr_load(destination,args)
    # use mechanize etc to get and parse

    # somehow I'd need to set this.responseText with the response etc.
    @harmony.execute_js(args['onSuccess']) if it_works and args['onSuccess']
    @harmony.execute_js(args['onFailure']) if !itworks and args['onFailure']

tl;dr: Is there a simple way for me to provide Ruby methods that can be called from the JS environment (specifically, overriding the ones in the JS environment)

Thanks in advance!

I got carried away and made something that works, how well it works I have no idea!

I'd appreciate your input!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment