Passenger(mod_rails) released

Filed Under (Rails, Ruby) by Leonardo Borges on 14-04-2008

Tagged Under : ,

Passenger(mod_rails) has been released.

The idea is to ease the pain on rails applications deployment. I tested myself and in less than five minutes I had my application working behind Apache!

I’m not going to say much here besides the fact that it seems like a really good option for rails deployment and people have been talking about it already, including DHH.

But I do recommend a read on the architecture overview document. Be sure to read it all, specially the part on handling concurrent requests.

To install, “it doesn’t get easier than” that.

Good job guys.

JRuby + DB2 + xQuery == bug?

Filed Under (JRuby, Rails, Ruby) by Leonardo Borges on 07-04-2008

Tagged Under : , ,

Update: Follow up link to this issue on JRuby’s Jira, here

As I told in my last post, it was time to give JRuby a serious try. So I took one of our rails projects at work and decided to migrate it to JRuby and see what happens.

We heavily use the XML capabilities of DB2 and this was a huge problem. Every query would work just fine through the activerecord-jdbc-adapter - part of the JRuby Extras . But every Xquery would gracefully fail!

After some debugging I got stuck and decided to get JRuby and activerecord-jdbc-adapter’s source to see what was happening.

As I could see, it has a bug -in my opinion - at the java part of the code. The jdbc-adapter is a bridge to allow Active Record to talk with databases through native JDBC drivers, so it’s normal that we do have a java part here. At this point, what the code does is to inspect the sql statement sent from ruby and decide if it’s a select, update or insert.

I fixed the problem and submitted a patch to rubyforge. I’m not sure if it’s the best solution or not, but now I got the xQueries working just fine.

I’d love to hear from people with similar environments whether this patch works for you or not. I’m sure I didn’t try every possibility.

If you wanna try it, just drop me a message (e-mail in the About page) and I can send the pre-compiled jar file - for activerecord-jdbc-0.8

You can also just check out the code and compile yourself. ;)

QCon 2008: slides available

Filed Under (Conferences, JRuby, Rails, Ruby) by Leonardo Borges on 04-04-2008

Tagged Under : , , ,

Most of last QCon’s presentations are available for download here.

Highlights to Ola Bini’s on JRuby(pdf) and Randy Shoup’s on eBay’s architectural principles(pdf).

And while we’re talking about JRuby, it’s impressive how it’s becoming a recurrent and big subject. Fast. It had its own small space at big event like QCon and in the last Euruko in Prague, we had a presentation by the JRuby Core Developers Charles Nutter and Thomas Enebo.

Big companies are sponsoring JRuby’s development indirectly or directly, like Sun. And other big companies are endorsing its production ready state, like Oracle, which has a publicly available website developed with JRuby On Rails.

It’s past the time to give it a serious try…

Euruko 2008: European RubyConf, Prague

Filed Under (Conferences, Rails, Ruby) by Leonardo Borges on 25-03-2008

Tagged Under : , ,

On friday I’ll be heading Prague for the European RubyConf.

Anyone is going? :)
Almost 300 attendees already registered for the event. And a few very interesting people will be speaking there like Matz and DHH (this one, through skype).

Besides that, the organization staff is scheduling 2 parties, friday and saturday, for the attendees.

Networking comes to mind, doesn’t it? I think it will be a great opportunity to meet interesting and bright people.

So, see u in Prague!

OpenID

Filed Under (Rails, Ruby) by Leonardo Borges on 18-02-2008

Tagged Under : ,

I think I’ve been really lucky lately. In my new job I’m getting to work with many interesting things and OpenID is just one of them.

We are investing high in Ruby on Rails and we have now a few internal applications in development stages. Our manager wanted the ability to let people log in to our rails applications(for now) using their OpenID accounts.

It was a funny task, as I knew very little about OpenID. The idea actually is really good. Instead of creating a new user account on each new service/site you’d like to subscribe to, you create a single user account in a OpenID provider - like MyOpenID - and use this identity to authenticate yourself in the services/sites that support this protocol.

What do we earn from that? Well, in my opinion, we can get a couple of benefits:

- You don’t need to memorize 723 logins and 723 passwords (if you really care about creating different passwords for all of your user accounts)

- You don’t authenticate yourself to the service you’re attempting to use. This service actually asks to your provider if your identity is valid, and you authenticate yourself there. Nowhere else.

I strongly recommend you visit the OpenID to understand more about it.

But, back to the problem, we needed to put it working in a rails app. And that’s when I found the ruby-openid library, provided by OpenID Enabled.

It is a complete library, really well documented that provides an abstraction layer both for consumer and server applications.

My first step was to develop the consumer. That’s what you need if you are going to provide your users with OpenID authentication in your web site. The ruby-openid library comes with several samples that really helped me out here. They were developed using Ruby On Rails and are a really good start point.

After this step, I was asked to evaluate the possibility of being a OpenID provider. At first I thought it would be a really complicated task, but again this ruby library had a great example of a simple provider. The drawback is that the samples were developed in an older version of Rails ( < 2.x ) . So I had to freeze the Rails version to 1.2.5 so I could run the provider sample code.

I am now working on porting this code to Rails 2.x, into one of our applications and it’s been flowing well so far. Just wanted to share this library for those of you trying something similar. It is really worth a look.

Rails 2.0: XML data type and DB2

Filed Under (Rails, Ruby) by Leonardo Borges on 02-01-2008

Tagged Under : ,

[2008/04/30] Update: The ibm_db gem has been updated to support the new Rails 2.0 style migration. Now you can just use t.xml and it will work. Look here for more info. Thanks to Mario Briggs for pointing me to the update.

In my new job we work with XML data natively stored on DB2. I have done some test with Rails and DB2 a few weeks ago and it’s pretty interesting, specially the easiness that Rails deals with XML.

We decided to test some new features of DB2 9.5 and I decided to test them with Rails 2.0.

So I created a new Rails app, configured the database.yml to use the idm_db gem and fired:

$ rake db:create

The output is nice but, the database isn’t there! I suppose it’s something with the gem that needs to be updated. But really don’t know about it. It just doesn’t work. But this will not hold us down. I will just create the database by hand and keep going with my tests.

After that, I created a new model XmlDocument, which has a column named data, of type XML. According to the new migrations syntax, my model’s migration would look something similar with this:

class CreateXmlDocuments < ActiveRecord::Migration
def self.up
create_table :xml_documents do |t|
t.xml :data
t.timestamps
end
end

def self.down
drop_table :xml_documents
end
end

Right? Ok, I fired up a terminal and lauched:

$ rake db:migrate

The output? Here it is:

== 3 CreateXmlDocuments: migrating ============================================
-- create_table(:xml_documents)
rake aborted!
undefined method `xml' for #

Yes, a big nice exception! The new migration syntax doesn’t allow you to do t.xml! But please don’t ask me why! :p
The solution? Well, although it’s weird - imo - , it’s also easy. You can mix the new and the old syntax in the same file. So our model’s migration will now look like this:

class CreateXmlDocuments < ActiveRecord::Migration
def self.up
create_table :xml_documents do |t|
t.column :data, :xml
t.timestamps
end
end

def self.down
drop_table :xml_documents
end
end

And that’s it! We’re ready to go! I didn’t find anything else different so far, besides what I described here. Hope this helps!

Rails 2.0: Scaffold

Filed Under (Rails, Ruby) by Leonardo Borges on 21-12-2007

Tagged Under : ,

Following the Rails 2.0 hype, I’ve been playing around with it and decided to share a first impression: Scaffolding is gone!

But wait, before you knock your head against the wall, let me tell you something: I lied :)
Scaffolding is not really gone. It’s just changed a bit.

How can I tell? Well, as a good developer I thought: “I’ll just create a scaffold with the new version and see what’s different”

I fired up a terminal, created a news rails application and generated a new model:

$ script/generate model Contact name:string email:string - yes you can do this in rails 2.0, and these fields get into your model’s migration!

Now the I have a new model, it’s time for a controller to manage it:

$ script/generate controller Contacts

So your controller would look something like this huh?

class ContactsController < ApplicationController
scaffold :contact
end

Well, too bad! The method scaffold is gone from ActionController::Base! And I’m not lying this time!

Now that the dynamic scaffold is gone, we’re left with the static one.
Ok, let’s try it then:

$ script/generate scaffold contact

And it won’t work again! ;) At the end of the output, you will get something like this:

Another migration is already named create_contacts: db/migrate/001_create_contacts.rb

It really means that if your model is meant to be used by a scaffold, you better generate it in the same line. It will fail, afaik, if the model previously existed. Destroy yout model and controller, and execute the following:

$ script/generate scaffold Contact name:string email:string

Done! Just run your migrations, startup your server and your new scaffold in rails 2.0 will be working gracefully!

It took me a while to discover this changes because I didn’t find it well documented. But maybe I was not looking in the right places. :)

RubyWorks: Production Stack for Rails

Filed Under (Rails, Ruby) by Leonardo Borges on 01-12-2007

Tagged Under : ,

Well, we all know how hard, or at least cumbersome, it can be to set up a production environment to deploy your applications. Besides all the hardware stuff like storages, links, routers you are still left with a huge amount of software configuration to handle. This often includes configuring things like clusters, load balancing and services monitoring - Including notification of interested parts in case of any failure. Pieces of software you have to tie up and make them work together.

But hey, ruby lovers, you may have a better way to get this going! Released by ThoughtWorks, RubyWorks is, as quoted from their website, a production application stack for Ruby On Rails applications. I decided to give it a try and I really enjoyed it.

First of all I didn’t want to mess with my actual configuration so I installed a new vm with Virtual Box. It has Ubuntu 7.10 on it, with 256MB of memory.

After installing RubyWorks - instructions on their website -, you get a new skeleton rails app up and running, being served by 4 mongrels that defaults to production environment! Impressed? There is more. A HAProxy is also set up in front of your mongrel servers acting as a load balancer.

Well, you probably want to monitor all that stuff huh? A monit web interface is waiting for your call on port 2812! It monitors all your mongrel servers - four by default - and your HAProxy, allowing you to measure CPU and Memory usage, among other things.

The coolest thing here is that all these softwares you would have to setup by hand are already working together, ready for production! Well, is it?

Going a little deeper, I deployed a database backed application to test this stack’s performance.

I used Siege to stress the app and I am very happy with the results! I compared it with a single mongrel running on production env and no proxy at all.

It is worth mentioning that having 4 mongrels running took my vm to 77% of memory usage, while a single mongrel took it to 38%.

Read the rest of this entry »