Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Charles Lowell
    @cowboyd
    Can you post the stack trace that you’re seeing as well as the contents of the error?
    Srikanth Kuppuswamy
    @Hospira-MedNet
    do u want to me paste the code here
    Charles Lowell
    @cowboyd
    that’s fine, or in a gist
    Srikanth Kuppuswamy
    @Hospira-MedNet
    this is the only code i have it in my .js file
    cxt.eval('f.foo(2)');
    when i run as js sample1.js , i am getting the exception - js: uncaught JavaScript runtime exception: ReferenceError: "cxt" is not defined.
    Charles Lowell
    @cowboyd
    cxt.eval(‘f.foo(2)’) should be in your ruby code.
    Srikanth Kuppuswamy
    @Hospira-MedNet
    then how i can call any ruby code in .JS file
    i read that rubyracer supports you can ruby methods in javascript
    you can call ruby methods in javascript
    Charles Lowell
    @cowboyd
    yes, you must first embed the ruby objects into the javascript context:
    main.rb:
    cxt = V8::Context.new
    cxt[‘f’] = Foo.new
    cxt.eval(File.read(‘sample1.js’), ‘sample1.js’))
    once you have setup the objects in your JavaScript context, then you can evaluate the javascript that you want to evaluate…. in this case sample1.js
    Srikanth Kuppuswamy
    @Hospira-MedNet
    so these 3 lines of code should be in sample1.js file
    Charles Lowell
    @cowboyd
    no, they are ruby code
    they should be in like main.rb
    therubyracer embeds javascript inside a ruby process, so you have to bootstrap from ruby
    Srikanth Kuppuswamy
    @Hospira-MedNet
    oh.. then u cannot directly call ruby methods in a class in javascript
    Charles Lowell
    @cowboyd
    yes, you can
    Srikanth Kuppuswamy
    @Hospira-MedNet
    now take the above 3 lines of code which we have in sample1.rb file
    now how i need to call this in sample1.js file
    Charles Lowell
    @cowboyd
    you start with ruby, you create aJS context, then you put zero or more ruby objects into the JS context, then you evaluate the JS which can call back to ruby
    you don’t call the file, you call objects
    you say ruby sample1.rb
    Srikanth Kuppuswamy
    @Hospira-MedNet
    i will tell my problem exactly..
    i have some ruby class which has some functions already written
    now i am writing protractor tests which is .JS file..
    now i need to call these available ruby methods in my .js file to reuse..
    Charles Lowell
    @cowboyd
    ah, in that case, you cannot use therubyracer because your process is a node process, not a ruby process :(
    Srikanth Kuppuswamy
    @Hospira-MedNet
    so how i can do this
    Charles Lowell
    @cowboyd
    you would need to embed a ruby interpreter into your node process. The Ruby Racer embeds javascript into a ruby process
    I’m not sure, you might want to try opalrb http://opalrb.org/
    It’s compiles ruby down to javascript, which you would then be able to call from your protractor tests.
    Srikanth Kuppuswamy
    @Hospira-MedNet
    i checked this one also
    i have a doubt where can u click this link - http://opalrb.org/docs/compiled_ruby/
    i know i am bugging u.. but plzz can u give me few mins of ur time plzz
    if u come down to section here - Ruby from Javascript
    where similarly u have a class foo .. which i stored in a ruby file
    now how i shd i make my call in .JS file?
    Charles Lowell
    @cowboyd
    I’m not an Opal expert, so I’d recommend asking inside the opal community, but from what I can tell, you have to compile your ruby using the opal compiler. That will produce some javascript. Eval that javascript, and then you can use the Opal.Foo.$new().$bar() syntax.
    Chris Seaton
    @chrisseaton
    Hi - I'm researching integration of Ruby and JS. I've asked around for how people are using The Ruby Racer, and mostly I've heard about asset pipelines. Is there anyone else using JS with more integration? So running snippets of JS in the middle of their Ruby app?
    Charles Lowell
    @cowboyd
    @chrisseaton I know the folks at discourse use it quite extensively, you might want to ask them.
    I’m actually thinking about using it as a JSON parser, and perhaps for doing static analysis on javascript code.
    Chris Seaton
    @chrisseaton
    @cowboyd yeah we were thinking about JSON parsing - thanks
    Bryan Wood
    @bryan-wood
    This message was deleted
    Charles Lowell
    @cowboyd
    This message was deleted
    Tenzin Chemi
    @imechemi
    Hi, I am facing problem with installing therubyracer gem. what is the compiler requirement for the v8 by rubyracer?
    I am on mac
    Tenzin Chemi
    @imechemi
    :worried: chatroom is inactive since oct 22
    Chris Seaton
    @chrisseaton
    Can you gist your error output
    Tenzin Chemi
    @imechemi
    sorry @chrisseaton I didn’t receive any notification and missed your response. I can’t track what happened before, but right now I got it fixed