This is just a quick post, will post a longer one later when I’ve had more time to play.
Before this will work, you’ll need to download and install JRuby, and copy jruby.jar from the installation directory to your Coldfusion classpath. For me those directories were c:\program files (x86)\jruby-1.4.0\lib and c:\Coldfusion9\lib respectively.
Once that’s done, on to the fun!
First, I created a really simple custom tag called ruby.cfm as follows:
<cfscript> ruby = createObject("java", "org.jruby.embed.ScriptingContainer"); if (thisTag.ExecutionMode is "end") { thisTag.GeneratedContent = ruby.runScriptlet(toString(thisTag.GeneratedContent)); } </cfscript>
Then, I created my test page, test_ruby.cfm:
<cfset name = "Bob" /> <cfoutput> <cf_ruby> def myproc(str) "Hello ##{str}!" end myproc("#name#") </cf_ruby> </cfoutput>
When you load up the test page in your browser, you should see:
Hello Bob!
WARNING: Running this code may cause a rip in the space-time continuum.
My boss was inquiring of me if one can use ruby with coldfusion. This came just at the right time. Thanks.
Glad I could help Don. I haven’t really done any in-depth experimenting with this, so there is probably a better way to do it. Please let me know how you make out!