Is there a place for java in Ruby on Rails apps?

Hi all,

I’m asking this question from the standpoint of a developer with almost
10
years experience with Microsoft technologies, mostly doing server side
component and database work. So, I’m not very familiar with the java
world. Can anyon tell me how/if java development can complement Ruby on
Rails development? I’m not interested in how java can duplicate Rails
functionality, but things like whether or not it makes sense to develop
server-side components in java to leverage in Rails apps. Is Rails by
itself a complete solution? Does ruby and Rails make java obsolete?

For some things I still find Java to be useful and easier to do things
with.
(before I get flammed) This is mainly because of the VAST amount of
libraries written in the Java world. If you have thought about, it’s
probably been done. Ruby isn’t quite there yet, but I’m sure it will
once
the popularity gets going.

For a practicle example, for the search process of things on a site I
did
recently was done with Java Lucene (a very well written/thoroughly
tested
framework). I was almost able to this completly with Ruby (using Ferret)
but
due to some minor niggles, was unable to.

Java still has its place. Ruby is gradually building its own place. Some
(I
agree) think Ruby’s place is easier to get around and has a
better/simplier
layout.

-Nick

Hi,

I have 1 controller with several actions and i need to show a layout
for some actions and another one for the others.

Any ideas??

Thanks,


Diego D. Lapiduz
www.sinai.com.ar
[email protected]

It is possible to do this with

render :layout => ‘yourlayout’

  • Marius

On Sun, May 14, 2006 at 10:27:07PM -0300, Diego L. wrote:

I have 1 controller with several actions and i need to show a layout
for some actions and another one for the others.

Any ideas??

There’s a way to specify which layout you want to use for a particular
render. I can’t remember if it’s on the render call or if there’s a
include/exclude option on the layout call, but it’s in the API manual –
that’s how I found it when I needed it a few months ago.

  • Matt

On 5/14/06, Matthew P. [email protected] wrote:

  • Matt

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Here’s what I do:

class MyController < ApplicationController
layout :choose_layout

protected
def choose_layout
if [ ‘signup’, ‘register’ ].include? action_name
‘application’
else
‘owners’
end
end
end

Pat

I believe Java can absolutely complement Ruby on Rails, especially when
running JRuby on Rails (which works now for the OnLamp.com “Rolling with
Rails” cookbook app). Tying in JDBC behind ActiveRecord, wiring up
existing
Java components and services, deploying Rails and J2EE apps
side-by-side.
It’s a win for both camps, and it’s running better and better every day.

I believe that while Java and J2EE provide very powerful services for a
deep, heavy, multi-server business tier, it still sucks royally for
anything
related to web applications. With JRuby, there’s a real potential now to
run
not only independent Rails apps on the JVM, but Rails apps as the web
frontend for an entire enterprise of services, with all the management,
clustering, replication, and failover those services provide.

Getting Rails to run on JRuby was only the beginning. Figuring out how
best
to use Rails on the JVM…that’s even more exciting.

Hi, eventhough Java has a vast number of libraries, it doesn’t mean
these libraries are needed within Ruby. Also, Java is nice but Ruby
shouldn’t try to be like Java. People tend to forget the VM came from
Smalltalk not Java. Also, one doesn’t need to or have to use Java and
J2EE for a deep, heavy, and multi-server business tier. In short,
Ruby should simply be Ruby and this leads to success in my mind
evolved from some of the best features of GREAT languages (i.e.
Smalltalk, LISP, and so on).

-Conrad

Terry D. wrote:

Rails make java obsolete?
Greetings. And welcome to the Light Side. I’m speaking from the role
of a Microsoft (on step 5 / 12 in MCSD Anonymous) and J2EE application
programmer. I have had some extensive experience with all this
stuff…and the wheels have been turning trying to figure it all out…

I believe that Ruby and Rails could make future development faster and
simpler. However, there are a huge amount of java apps out there.
Hopefully they’ve been well written and communicate in a well-structured
manner with a database. If you can assume these conditions, you should
be able to design and write a very decent RoR front-end to a java-backed
database quickly and get rid of your jsp stuff. :slight_smile: I am actually
trying to determine how to do this with a large J2EE app.

For new development, I think you could do much of what J2EE apps do in
the background, on the server-side, with pure Ruby. Then similarly use
the Rails framework for the web front-end portion. As another person
pointed out, this could be probably be determined based on the amount of
available libraries to perform the required functionality. Java might
be best, Ruby might be best. (I suppose, if you wanted, you could even
use a .NET or legacy MS dev environment for this…for those S&M types
out there.) If you had to code it from scratch, I would have to say
Ruby would have a huge advantage in my book. Honestly you could use a
different language behind each application server / web service if you
really wanted to. But…damn! (Hope you have good mental health
insurance, you’ll need it.)

Regardless, I see no reason they couldn’t co-exist. In fact someone had
asked about a traditional three-tier solution a while back. I see J2EE
/ Ruby Application Servers as a portion of this. If you have some
complex (or lengthy) application logic, utilize the Rails front-end to
drop an event into a monitored table and let an application server
process it, reporting progress / completion to be fed back to the
front-end. Clean. Fast.

Tier 1 - Database Server (Postgres / MySQL / MSSQL / etc)
Tier 2 - J2EE (JBoss / WEBSphere / etc) -or- Ruby Applications (Web
Services, perhaps)
Tier 3 - RoR (standard front-end)

However, I wouldn’t always make internal Tier 3 call through Tier 2 to
hit the databases… You could implement that if you were paranoid or
obsessive-compulsive… (Or even just had standards better than
mine…) I don’t consider it worth the overhead… And if people are
working on my systems they will damn well follow my guidelines or risk
staying late with me…and buying me dinner… :slight_smile: Seriously though,
this is called “Agile Communications” (ok I probably just made that up)
and should be practiced regularly. Anything the “outside world”
accesses would be accessed through a Web Service at Tier 2 so I could
control it.

I hope to have it working within the year. :slight_smile:

-Curtis

Adam K. wrote:

Where I’m at, we have a Whole Lot of Java code that we’re not going
to dump anytime soon. I’ve found that rjb[1] coupled with RMI is a
very thin solution to interop.

rjb allows me to embed a Java VM inside my Ruby process. From
there I call the client side of our RMI API to talk to the rest of
our code. I wrote a require_jvm helper to make grabbing Java classes
easier; the whole layer between Java and Ruby is about 50 lines of
code (plus the rjb extension).

Does it means it could be quite easy to do some interaction between a
rails app and, let’s say, a java search engine ?

In that case (interfacing with a search engine, I take this example
because it’s easier for me to understand) what is the Java architecture
counterpart ? I hope it does not mean running a Tomcat instance just to
have access to the Java services ? Is there a ‘lighter’ solution ?

On May 15, 2006, at 12:46 AM, Curtis S. wrote:

Tier 1 - Database Server (Postgres / MySQL / MSSQL / etc)
Tier 2 - J2EE (JBoss / WEBSphere / etc) -or- Ruby Applications (Web
Services, perhaps)
Tier 3 - RoR (standard front-end)

Where I’m at, we have a Whole Lot of Java code that we’re not going
to dump anytime soon. I’ve found that rjb[1] coupled with RMI is a
very thin solution to interop.

rjb allows me to embed a Java VM inside my Ruby process. From
there I call the client side of our RMI API to talk to the rest of
our code. I wrote a require_jvm helper to make grabbing Java classes
easier; the whole layer between Java and Ruby is about 50 lines of
code (plus the rjb extension).

If embedding a Java VM in your Ruby process feels distasteful, check
out Hessian[2]. It implements a binary RPC protocol over HTTP.
There is a Ruby gem implementing the client side of it. I found it
was pretty easy to get going.

I highly recommend this stuff. If anyone is interested, I can go
into further details.

[1] http://mvm.therealadam.com/articles/2006/03/26/enterprise-
integration-with-ruby-saves-my-ass
[2] Hessian Binary Web Service Protocol


~akk

I’m working on a very large Ruby on Rails application (dare I say it -
enterprisey?), but there are a few things that I needed to do in .NET.
I know that it’s not Java, but from what I understand the
technologies are similar (I’ve never touched Java at all).

The main thing was interacting with my organizations Active Directory.
Instead of going through the trouble of making sure my production
linux server was part of the domain and could access the Active
directory, I just stuck a secure webservice up with the two functions
I needed and call those from my Controllers. While not the most
beautiful solution, it does allow me to continue building things
quickly.

So in that sense, .NET really helped in building my RoR application.

Josh

This has been discussed about before. Do a search for Lucene and/or
Ferret
and you should get some results. I’ve also written about my experinces
as
well:

http://blog.nicholasstuart.com/articles/2006/02/11/a-little-bit-of-both