You are currently browsing the tag archive for the ‘rails’ tag.
I have a Rails 1.2.3 application running in JRuby 1.0.1 on Tomcat 5.5.9 at work. The application itself is not mine (actually Tim‘s), but I helped him to run it in JRuby on Tomcat so that we can utilize the existing infrastructure at work.
After I’ve got the Rails 2.0 development tools working, as recommended, I have upgraded the application to Rails 1.2.6 and successfully run it in JRuby 1.0.3 on Tomcat 6.0.10 with ActiveRecord -JDBC 0.7 and goldspike 1.4. I haven’t seen any deprecation warnings so far, which is a good sign.
Here are some short tips (and notes for myself) so far:
- As mentioned in Nick’s post, for Rails 1.2.x to use the AR-JDBC 0.7, you need to add the followings into “config/environment.rb” in the usual spot above the “Rails::Initializer”, for example
RAILS_CONNECTION_ADAPTERS = %w(jdbcmysql)
- Use the absolute path with RAILS_ROOT when accessing a file directly. This is because the working directory of the webapps is different from when the rails app is running in WEBrick or mongrel.
- Consolidate logging into one stream by configuring the both Tomcat and Rails logging to STDOUT. In “config/environment.rb” insert the followings right after the “Rails::Initializer.run do |config|” line. I also disable the colorized log messages to make them readable in the Eclipse console window.
config.logger = Logger.new(STDOUT)
config.active_record.colorize_logging = false
- I don’t use the goldspike plugin that provides tasks to package up a web archive. Instead, I use the static web.xml without “jruby.home” and “rails.env params” to make the web archive deployment environment independent. Instead I set JRUBY_HOME and RAILS_ENV.
- In general, use Gems On Rails – “vendor everything”, which allows you to push dependent gems into your rails app thus ensuring your application will be guaranteed to work when deployed. This makes the deployment much easier even at work place. My team provides application hosting environments where only core gems are installed.
- JRuby 1.0.3: No Java-based extension library backward compatibility – by Nick Sieger
So I have tried this again – JRuby on Rails in Eclipse IDE with WebTools Platform and RadRails.
Since RadRails 0.9.1 which has fixed compatibility issues with Eclipse 3.3 was out in November, I have upgraded Eclipse to 3.3.1 with WebTools Platform 2.0.1. I have also upgraded Tomcat to 6.0 as WTP 2.0 supports it.
ActiveRecord-JDBC 0.7 and GoldSpike 1.4 are just out, too. Basically I have upgraded everything and they have worked well together. I am going to upgrade or maybe re-write a few of my old rails apps in this development environment. How exciting!
Originally uploaded by Lucee.
In my previous post, I’ve re-written my old Java JMX client program in JRuby with Jetty.
In other area of my old Java program, I chose the data-push model, calling a set of JMX commands periodically and publishing data onto JMS, because I did not want them called too much frequently by accident. It has worked well, but there are a few things I wanted to change like, 1) It can’t run another instance for redundancy, 2) it’s not simple to get data because of JMS.
So, this time I’ve chosen the data-pull model with embedded HTTP servlet container jetty, implementing JSON webservice.
I also chose data caching without database backend in the JBoss webapp that subscribes to the JMX data on JMS. I admit I made a wrong decision on that. The data became stale from time to time and the JBoss server needed to restart to resolve the problem.
This time, as you would expect, I’ve chosen MySQL since I am thinking to rewrite the webapp in Rails.
The point of this post is how I gather data for a Rails application.
What I need is to gather data every minute. There are a few ways to run background jobs in Rails, but there is a better and simpler way to do that, which is running Rake tasks using Active Records from Cron. There is a great tutorial on that from Rails Envy.
Each task takes 15-20 secs to complete. Anything could go wrong and more than one task would run at once, which would make the problem worse. How can I prevent this? Lockrun comes handy here. Lockrun serves as a protective wrapper and it insures that another instance of the same command is not already running. My co-worker Phil has been using this for his applications for sometime now.
I have already managed to run an example of JRuby on Rails in Tomcat with PKI at work. So what I need next was an application development environment and I’ve got JRuby on Rails running on Tomcat inside Eclipse IDE with Eclipse WebTools Platform and Aptana’s RadRails plugin.
I already have a Tomcat package coupled with JASS (Java Authentication and Authorisation Service) framework at work, which works nicely within Eclipse IDE with WTP. So, I just needed to install RadRails as a plugin to that. I can only use RadRails to develop a Rails app, but can’t run it in WEBrick because it calls Java JASS API functions to get out other information about the user. However, you can add it to a Tomcat server as an external web module (you can’t add this as a web module because it’s not a web project, but a rails project) so that you can run the Rails app with JRuby in Tomcat within Eclipse! Here is a short instruction.
- Download the Eclipse + WTP all-in-one package
- Install RadRails and configure it
- Create a new Rails project
- Create a WEB-INF folder with necessary files in the root of the project
- Create a new server (e.g. Tomcat)
- Add the Rails project as an external web module to the server. You just point the directory where the Rails project resides in and give a path like /projectname.
- Start the server
- Open a browser in Eclipse and access the webapp (screenshot)
“Drop Rails into TomCat and it just works” – Ola Bini
“JRuby is ready for prime time. Application developers should try their applications on JRuby NOW” – Ola Bini
I had a minor problem with its installation, but I’m impressed very much when I’ve got JRuby-0.9.9, Rails-1.2.3, Tomcat-5.5.9 and PKI framework at work working together nicely. A big thank you to the JRuby team.
The problem I had was nothing to do with JRuby, but Subversion. I could not checkout the rails-integration at work since the svn protocol was blocked (“Unknown hostname ‘rubyforge.org'” error) and RubyForge did not allow the checkout over http (405 Method Not Allowed error). When I tried it on a work laptop at home, it still did not work ( Can’t connect to hose ‘rubyforge.org’: A connection attempt failed because the connected party did not properly respond after a period of time, or …). In the end I had to disable a firewall software. Hope this saves someone else’s time.