Forum: Ruby eRuby/erb outside of Rails

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.
0a5d1ad3f4e34d2de3472e344bbbd342?d=identicon&s=25 Jonny Noog (jonny_noog)
on 2008-11-28 01:15
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.
A57b61a5b35b432421fdd6d6514c9ad7?d=identicon&s=25 Post Tudbc (tudbc)
on 2008-11-28 02:44
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.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2008-11-28 03:22
(Received via mailing list)
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 Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
0a5d1ad3f4e34d2de3472e344bbbd342?d=identicon&s=25 Jonny Noog (jonny_noog)
on 2008-11-28 04:07
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 Biedenharn 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.
A57b61a5b35b432421fdd6d6514c9ad7?d=identicon&s=25 Post Tudbc (tudbc)
on 2008-11-28 05:14
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.
0a5d1ad3f4e34d2de3472e344bbbd342?d=identicon&s=25 Jonny Noog (jonny_noog)
on 2008-11-28 05:26
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. :)

I will have to look into it further. Thanks.
F472b397918df02e70d8d7d0cf086c00?d=identicon&s=25 Dick Davies (Guest)
on 2008-11-28 11:18
(Received via mailing list)
Why would you use this rather than Warbler (for example)?
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2008-11-28 14:24
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.
A57b61a5b35b432421fdd6d6514c9ad7?d=identicon&s=25 Post Tudbc (tudbc)
on 2008-11-29 03:05
Dick Davies 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/TudbcJRubyServletD...

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.
0a5d1ad3f4e34d2de3472e344bbbd342?d=identicon&s=25 Jonny Noog (jonny_noog)
on 2008-11-30 23:11
I appreciate the further suggestions and comments. Thanks very much. :)
491fa09e8756146e94b0c81bd2cd1761?d=identicon&s=25 Cyrus Broka (cyrus007)
on 2008-12-03 22:25
Jonny Noog wrote:
> I appreciate the further suggestions and comments. Thanks very much. :)

Have you checked out sinatra @ http://sinatra.rubyforge.org/
6d3c187a8b3ef53b08e3e7e8572c4fea?d=identicon&s=25 Jeremy McAnally (Guest)
on 2008-12-03 22:54
(Received via mailing list)
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 Broka <swapan@yahoo.com> wrote:
> Jonny Noog wrote:
>> I appreciate the further suggestions and comments. Thanks very much. :)
>
> Have you checked out sinatra @ http://sinatra.rubyforge.org/
> --
> Posted via http://www.ruby-forum.com/.
>
>



--
http://jeremymcanally.com/
http://entp.com/
http://omgbloglol.com

My books:
http://manning.com/mcanally/
http://humblelittlerubybook.com/ (FREE!)
0a5d1ad3f4e34d2de3472e344bbbd342?d=identicon&s=25 Jonny Noog (jonny_noog)
on 2008-12-15 04:46
I had not heard of either Vintage or Sinatra. Thanks again!
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2008-12-15 13:12
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/...

"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 :-)
A57b61a5b35b432421fdd6d6514c9ad7?d=identicon&s=25 Post Tudbc (tudbc)
on 2008-12-27 01:34
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.
6d3c187a8b3ef53b08e3e7e8572c4fea?d=identicon&s=25 Jeremy McAnally (Guest)
on 2008-12-27 01:41
(Received via mailing list)
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. :(

--Jeremy

On Mon, Dec 15, 2008 at 6:04 AM, Brian Candler <b.candler@pobox.com>
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 :-)
> --
> Posted via http://www.ruby-forum.com/.
>
>



--
http://jeremymcanally.com/
http://entp.com/
http://omgbloglol.com

My books:
http://manning.com/mcanally/
http://humblelittlerubybook.com/ (FREE!)
9d751d4cd704a4efe3a335c77c4487a3?d=identicon&s=25 Dave Bass (dogsbody)
on 2008-12-28 12:44
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
Fd22ee3cfc7dac283ce8e451af324f7d?d=identicon&s=25 Chad Perrin (Guest)
on 2008-12-30 05:48
(Received via mailing list)
On Sun, Dec 28, 2008 at 08:43:45PM +0900, Dave Bass 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.
This topic is locked and can not be replied to.