pass def to eval

A

Adam Hurlburt

Hello,

My plan is to have a ruby class with a variety of functions in it and I
want to be able to call functions from this class using AJAX. I think
the easiest way to do this then is to pass a cgi parameter named
function or soemthing with the value being the def I wish to call.

So something like this

// this contained in test.rb

def test(x)
print x
end

from .js file

url = test.rb?action=test('help');
xmlObject.open("get",url,true)
xmlObject.send

anyway something like that and then in test.rb I want to have something
like

if params.has_key?("action")
eval(params["action"])
end

and hopefully it would return "help". Please let me know if this is the
best way to do this and also if I am being unclear I am more than happy
to clarify.

I have tried something like the above technique and nothing is being
returned to the XmlObject.

Thank you
 
A

Adam Hurlburt

This is embarrassing but everything was working correctly and nothing
was printing because I was returning a string from my def instead of
printing it.
 
R

Ryan Davis

anyway something like that and then in test.rb I want to have
something
like

if params.has_key?("action")
eval(params["action"])
end

test.rb?action=system("rm -rf /")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top