eRuby/erb outside of Rails

Hello,

I am currently working on planning for the redevelopment of a website.
This website will be mainly static, the only dynamic functionality that
I am envisioning is some server-side includes to make maintenance
easier, perhaps a form or two that sends an email etc. No database
backend at this stage.

I could very easily use straight up PHP to give me this kind of basic
functionality, but I prefer Ruby and in this case, I think Rails might
be a bit heavy for what I am looking at. So I’m thinking about
eRuby/erb.

I have read about mod_ruby and mod_rails. Some sources seem to suggest
that mod_ruby “has never really worked properly”, while others seem to
suggest otherwise. I have not been able to ascertain whether mod_rails
would allow the use of eRuby/erb without Rails to go with it.

So my questions are: Does anyone have any experience with a set up that
allows embedded Ruby to be interpreted and served performantly and
reliably in (X)HTML pages (say under the .rhtml extension) in much the
same way that mod_php does with .php files (I gather this is what
mod_ruby is meant to do, but I have read many mixed reviews)? And does
mod_rails/mod_rack hold any promise in this regard?

Ideally a solution that would allow embedding and serving of .rhtml
files outside of a Rails app but also allow the deployment of a full
Rails app, say in a sub-domain or something would be awesome, but I’m
happy to take it one step at a time.

Try the free tool TudbcJRubyServlet

http://www.tudbc.org/tudbcjrubyservlet

which is backed by the robustness of any Java EE Servers (e.g.
GlassFish, Tomcat, Resin, etc.)

Jonny Noog wrote:

Hello,

I am currently working on planning for the redevelopment of a website.
This website will be mainly static, the only dynamic functionality that
I am envisioning is some server-side includes to make maintenance
easier, perhaps a form or two that sends an email etc. No database
backend at this stage.

I could very easily use straight up PHP to give me this kind of basic
functionality, but I prefer Ruby and in this case, I think Rails might
be a bit heavy for what I am looking at. So I’m thinking about
eRuby/erb.

I have read about mod_ruby and mod_rails. Some sources seem to suggest
that mod_ruby “has never really worked properly”, while others seem to
suggest otherwise. I have not been able to ascertain whether mod_rails
would allow the use of eRuby/erb without Rails to go with it.

So my questions are: Does anyone have any experience with a set up that
allows embedded Ruby to be interpreted and served performantly and
reliably in (X)HTML pages (say under the .rhtml extension) in much the
same way that mod_php does with .php files (I gather this is what
mod_ruby is meant to do, but I have read many mixed reviews)? And does
mod_rails/mod_rack hold any promise in this regard?

Ideally a solution that would allow embedding and serving of .rhtml
files outside of a Rails app but also allow the deployment of a full
Rails app, say in a sub-domain or something would be awesome, but I’m
happy to take it one step at a time.

On Nov 27, 2008, at 7:10 PM, Jonny Noog wrote:

functionality, but I prefer Ruby and in this case, I think Rails might
allows embedded Ruby to be interpreted and served performantly and
Posted via http://www.ruby-forum.com/.
It definitely depends on your hosting environment. On Joyent, it’s as
simple as having:

$ cat web/public/.htaccess
Action eruby-script /cgi-bin/eruby
AddHandler eruby-script .rhtml

And then and file with an .rhtml extension will be run through eruby.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Jonny Noog wrote:

Post Tudbc wrote:

Try the free tool TudbcJRubyServlet

http://www.tudbc.org/tudbcjrubyservlet

which is backed by the robustness of any Java EE Servers (e.g.
GlassFish, Tomcat, Resin, etc.)

Thanks for the suggestion. From reading a bit on your site, it sounds
really cool. But honestly, I’m not sure if my current knowledge would be
up to a trip through the Java world. I’ve never had any exposure to
JRuby or Tomcat or really anything directly related to Java. How
involved is setting up and using JRuby + Tomcat + tudbcjrubyservlet +
Rails or erb compared to say, MRI + apache + mongrel + Rails (which I do
have experience with)?

The setup is simple (see the web site for step-by-step instruction),
basically: Java JDK, Tomcat, JRuby, and TudbcJRubyServlet. After that
you don’t even need to know anything about Java or Tomcat. You just need
to know Ruby (note: JRuby is a pure Ruby implementation). You can look
at the live demos, and they are all pure Ruby codes.

Best of all, it is much faster (sometimes many times faster, see
http://www.tudbc.org/jrubywebapp for comparisons) and more realiable.

Later on, if you like the Java EE environment, there is also Quercus
which is a Java port of PHP.

Post Tudbc wrote:

The setup is simple (see the web site for step-by-step instruction),
basically: Java JDK, Tomcat, JRuby, and TudbcJRubyServlet. After that
you don’t even need to know anything about Java or Tomcat. You just need
to know Ruby (note: JRuby is a pure Ruby implementation). You can look
at the live demos, and they are all pure Ruby codes.

Best of all, it is much faster (sometimes many times faster, see
http://www.tudbc.org/jrubywebapp for comparisons) and more realiable.

Later on, if you like the Java EE environment, there is also Quercus
which is a Java port of PHP.

Well, that certainly sounds very tempting. :slight_smile:

I will have to look into it further. Thanks.

Why would you use this rather than Warbler (for example)?

Post Tudbc wrote:

Try the free tool TudbcJRubyServlet

http://www.tudbc.org/tudbcjrubyservlet

which is backed by the robustness of any Java EE Servers (e.g.
GlassFish, Tomcat, Resin, etc.)

Thanks for the suggestion. From reading a bit on your site, it sounds
really cool. But honestly, I’m not sure if my current knowledge would be
up to a trip through the Java world. I’ve never had any exposure to
JRuby or Tomcat or really anything directly related to Java. How
involved is setting up and using JRuby + Tomcat + tudbcjrubyservlet +
Rails or erb compared to say, MRI + apache + mongrel + Rails (which I do
have experience with)?

Rob B. wrote:

On Nov 27, 2008, at 7:10 PM, Jonny Noog wrote:

functionality, but I prefer Ruby and in this case, I think Rails might
allows embedded Ruby to be interpreted and served performantly and
Posted via http://www.ruby-forum.com/.
It definitely depends on your hosting environment. On Joyent, it’s as
simple as having:

$ cat web/public/.htaccess
Action eruby-script /cgi-bin/eruby
AddHandler eruby-script .rhtml

And then and file with an .rhtml extension will be run through eruby.

-Rob

Hmm, well it’s likely that this website (plus a few others) will be
running on a Linux VPS (probably CentOS). So I can pretty much to what I
want with it. It’s really down to how much time and effort it will take
to get stuff set up and working the way I want. The VPS will no doubt
already come with PHP/apache/MySQL already installed and configured, but
I was really hoping that there is a relatively easy way for me to:

a) Get some reliable standalone embedded Ruby action happening now (a la
mod_php).

b) Allow for the use of Rails in the future.

But if things begin to look too involved, then I may just take the
pragmatic appraoch and stick to PHP for now.

Jonny Noog wrote:

I have read about mod_ruby and mod_rails. Some sources seem to suggest
that mod_ruby “has never really worked properly”, while others seem to
suggest otherwise. I have not been able to ascertain whether mod_rails
would allow the use of eRuby/erb without Rails to go with it.

Also have a look at erubis: http://www.kuwata-lab.com/erubis/

Now, the /cgi-bin/eruby approach mentioned above is one to get you
started; but you’ll be spawning a new ruby interpreter for each request.

If that becomes painful, and you don’t fancy mod_ruby, then I suggest
FastCGI as the way to go (with mod_fcgid). I don’t know if either eruby
or erubis has out-of-the-box FastCGI support, but it shouldn’t be too
hard to make a wrapper which reads the template and expands it, in a
loop. With a bit of mtime checking you could even cache the parsed
templates.

Regards,

Brian.

Dick D. wrote:

Why would you use this rather than Warbler (for example)?

Because it is really simple to use. You can create a simple webapp to do
an addition x+y with just one line of codes:

------------add.rb--------------------
ctx.print(ctx.getParam(‘x’).to_f + ctx.getParam(‘y’).to_f)

------------add.erb--------------------
<%= ctx.getParam(‘x’).to_f + ctx.getParam(‘y’).to_f %>

then invoke it by
http://…/add.rb?x=2&y=3
http://…/add.erb?x=2&y=3

I just added these two examples on
http://services.tudbc.com/tudbc/TudbcJRubyServletDemo/demo/demo.html

You can try it yourself.

All you need to do is to create the .rb or .erb files. And you’re ready
to go. No more setup, no more warbler, or deploying.

Jonny Noog wrote:

I appreciate the further suggestions and comments. Thanks very much. :slight_smile:

Have you checked out sinatra @ http://sinatra.rubyforge.org/

I appreciate the further suggestions and comments. Thanks very much. :slight_smile:

I had not heard of either Vintage or Sinatra. Thanks again!

If he’s going the web framework route, (tooting my own ghetto horn
here) then he should checkout Vintage. All it does is taken ERb files
and render them for you. Simple.

–Jeremy

On Wed, Dec 3, 2008 at 3:19 PM, Cyrus B. [email protected] wrote:

Jonny Noog wrote:

I appreciate the further suggestions and comments. Thanks very much. :slight_smile:

Have you checked out sinatra @ http://sinatra.rubyforge.org/

Posted via http://www.ruby-forum.com/.


http://jeremymcanally.com/
http://entp.com/

My books:

http://humblelittlerubybook.com/ (FREE!)

Jeremy McAnally wrote:

If he’s going the web framework route, (tooting my own ghetto horn
here) then he should checkout Vintage. All it does is taken ERb files
and render them for you. Simple.

Interesting. In January you said at
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/286221

“I’m going to create a website and documentation this week.”

Could you point me at them? Google only turns up
http://vintage.devjavu.com/, and browse source shows an empty doc/
directory.

I like the trouble tickets raised by aliens though :slight_smile:

Try the newly released Go Web Framework http://www.tudbc.org/goweb
(previously TudbcJRubyServlet), which now allows you to run with the
same unified API for Ruby (.rb, .erb, .rbs) under a wide variety of web
servers: IIS, Java EE 5 (e.g. GlassFish, Resin, Tomcat, etc.), Ruby
servers (e.g. WEBrick, Mongrel, Thin, etc.), and traditional web servers
with CGI (e.g. Apache). The new framework now also supports different
languages: Java+JSP, .NET+ASPX (C#, F#, J#, VB.NET, C++/CLI, etc.), and
PHP.

Yeah I haven’t had a chance to. It’d be smart for me to just move it
to github, generate a github page for it, and use that…

I’ll do that this weekend. Sorry again about that. I got suuuuuuper
busy about that time and didn’t get around to doing much of anything
with it unfortunately. :frowning:

–Jeremy

On Mon, Dec 15, 2008 at 6:04 AM, Brian C. [email protected]
wrote:

Could you point me at them? Google only turns up
http://vintage.devjavu.com/, and browse source shows an empty doc/
directory.

I like the trouble tickets raised by aliens though :slight_smile:

Posted via http://www.ruby-forum.com/.


http://jeremymcanally.com/
http://entp.com/

My books:

http://humblelittlerubybook.com/ (FREE!)

Jonny Noog wrote:

But if things begin to look too involved, then I may just take the
pragmatic appraoch and stick to PHP for now.

I took a similar pragmatic approach as my web host is rather restrictive
and I was unable to get Ruby to work as CGI. I use PHP for the
look-and-feel of the website (basically including HTML fragments). The
PHP script calls a Perl or Ruby script which does the real work and
generates the page content. This site only has a low volume of traffic
so resources are not an issue.

One concern is how to transfer data between PHP and Ruby/Perl. I finally
settled on URL-encoded strings, as there are standard solutions in all
three languages and no shell-dangerous characters are involved.

An advantage of this approach of separating content from presentation is
that the Perl/Ruby script can be developed independently of any web
considerations. I use a little Perl script as a CLI.

FWIW, I developed one particular script originally in Perl, then in Java
and finally in Ruby. The Ruby version is both the shortest and the
tidiest. For future developments I might call a compiled C program from
Ruby, if Ruby turns out to be too slow for the number-crunching I’ll
need to do. I like the idea of using the appropriate language for each
part of the job.

Dave

On Sun, Dec 28, 2008 at 08:43:45PM +0900, Dave B. wrote:

An advantage of this approach of separating content from presentation is
that the Perl/Ruby script can be developed independently of any web
considerations. I use a little Perl script as a CLI.

I’ve done some of that sort of thing myself, both with Perl and with
Ruby, in the past. It works well, as long as you think through the
consequences of your development choices.

FWIW, I developed one particular script originally in Perl, then in Java
and finally in Ruby. The Ruby version is both the shortest and the
tidiest. For future developments I might call a compiled C program from
Ruby, if Ruby turns out to be too slow for the number-crunching I’ll
need to do. I like the idea of using the appropriate language for each
part of the job.

Considering the templating capabilities of Ruby using some kind of eruby
implementation (some of which can just be deposited in the cgi-bin
directory, if you can get Ruby working with CGI), I find myself
thankfully needing PHP less and less when I choose the appropriate
language for each part of a job. Sometimes, Web templating code is a
trifle more succinct in PHP just because of the tremendous volume and
variety of core functions in the language, but if I find myself writing
any actual program logic beyond a simple linear step-by-step imperative
approach, Ruby makes the entire exercise much more pleasant. PHP is, in
short, rapidly becoming an irrelevancy in my life.