rubyjs / mini_racer

Minimal embedded v8
MIT License
594 stars 93 forks source link

Undefined Conversion #291

Open kirqe opened 1 year ago

kirqe commented 1 year ago

What is the alternative of ctx[key] = value that was available in rubyracer?

In rubyracer, the following block would return hi 1

ctx = MiniRacer::Context.new
person = Person.first
ctx[:person] = person
ctx.eval("'hi' + person.id")

I have tried the following things:

ctx.attach("person", proc{ person })

[8] pry(#<...>)> ctx.eval("person")
=> #<MiniRacer::JavaScriptFunction:0x0000000123b1d220>

[9] pry(#<...>)> ctx.eval("person.name")
=> ""

[10] pry(#<...>)> ctx.eval("person.id")
=> nil

[11] pry(#<...>)> ctx.eval("person()")
=> "Undefined Conversion"

What is the correct way to do what I've described above with mini_racer?

Thank you!

edit Not exactly what I need but this kinda works(not for relations though eg person().address)

ctx.attach("person", proc{person.serializable_hash})
ctx.eval("person().id")