I'm looking for some solution of next problem: Now i'm developing an Rails app. I want to have possibility to code in Ruby at browser and then execute that code in my Rails app.
Are there some ready solutions?
UPD:
- what about code highlighting?
- what about Native Client?
-
3is that a huge security breach that i smell ?m_x– m_x2012年01月19日 08:15:50 +00:00Commented Jan 19, 2012 at 8:15
-
Native Client in C++, not ruby.Raynos– Raynos2012年01月19日 09:09:41 +00:00Commented Jan 19, 2012 at 9:09
-
@Raynos code.google.com/p/nativeclient/source/browse/trunk/src/…falinsky– falinsky2012年01月19日 09:11:08 +00:00Commented Jan 19, 2012 at 9:11
-
@falinsky interesting, I guess you could do it that way. But why would you want to execute ruby in a browser environment?Raynos– Raynos2012年01月19日 09:14:10 +00:00Commented Jan 19, 2012 at 9:14
-
@Raynos actualy i need to get valid ruby code from web page and execute it server-side. though i'm not sure about native clientfalinsky– falinsky2012年01月19日 09:29:42 +00:00Commented Jan 19, 2012 at 9:29
3 Answers 3
https://github.com/codegram/rack-webconsole
Or you could simply pass the Ruby code to the server via post and call eval eval(CODE).
You should note that especially the second way is very insecure since it gives the executing code complete access to your system.
If this really has to be done "Locking Ruby in the Safe" could help secure it.
EDIT:
For syntax highlighting take a look at Code Mirror and ACE. Both are decent source code editors with ruby support.
Comments
There aren't really any real-world deployable solutions for this yet, but you might look at text/x-ruby as a proof of concept.
There's also the Cloud9 IDE which functions as a browser-based IDE, and will persist code back to your server to be run.
Comments
eval is what you are looking for. A user enters Ruby-code, which gets POSTed to your rails app. Inside your controller you will need to eval the submitted Ruby code.
But. You probably don't want this. If there really seems to be a need to evaluate and run user submitted code, you most probably will need to re-think the need for that feature. This is almost impossible to make secure. And even when you secure it from certain users, it can be exploited trough XSS; which can actually take over a server in no-time trough this "feature".
Comments
Explore related questions
See similar questions with these tags.