Forum: Ruby pass def to eval

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9397b7fcfdce4869a017107edf0e88c1?d=identicon&s=25 Adam Hurlburt (dark_helmut)
on 2008-10-27 23:57
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
9397b7fcfdce4869a017107edf0e88c1?d=identicon&s=25 Adam Hurlburt (dark_helmut)
on 2008-10-28 01:19
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.
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2008-10-28 01:54
(Received via mailing list)
On Oct 27, 2008, at 15:57 , Adam Hurlburt wrote:

> 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 /")
9397b7fcfdce4869a017107edf0e88c1?d=identicon&s=25 Adam Hurlburt (dark_helmut)
on 2008-10-28 02:03
Ryan Davis wrote:

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

Oh thank you Ill try that.
This topic is locked and can not be replied to.