Glassfish + jRuby + Rails3 + Multistage environments

Deploying to a multistage environment stack is so common there is even a nice Capistrano extension for it. However, if you decide to run Rails3 in jRuby with a deployment on glassfish forget all that nonsense. Glassfish is coded to only work with a rack file in Development, Test, or Production.

I hacked up my installed glassfish deployment modifying the rackup.rb file, however, I have not had time yet to dive into the bowels of glassfish-gem to figure out where it gets this import file from. I am sure it is a dependent gem of some sort, but I will save that for a future blog update.

Did a little more digging related to another glassfish problem and got a more definitive answer. Several problems I was facing were related to glassfish-gem and the fact that is no longer being maintained, which isn’t obvious from the commit history, but there are several fatal bugs in glassfish-gem that just are not going to be fixed.

There are several options available but I decided to go with Trinidad. It seems to be well written (so far) and is easier to configure. Also worked with my multi-stage environment too.

So while jRuby still can be maddening some days, it’s greener today than it was yesterday.

Posted in Uncategorized | 2 Comments

Revising my position on jRuby

In my earlier article Ruby on Rails vs. Java I put down jRuby and kind of being a niche option for organizations that want to get around their limitations put on my management. In the months since writing that article I have been working with jRuby so that I could take advantage of the Neo4j library. I still maintain that like trying to put Ruby on a legacy database you have to work harder, however, there are some strengths to jRuby. My experience has been that it runs faster and uses a smaller memory footprint (under load) than using Passenger/nginx. It still is a pain to use. I had issues with native extensions more than once, and it runs slower on my development system. The newest jRuby 1.6 seems pretty good, but still hitting some nasty bugs, some of which have been around since 1.5.2. So if you are using libraries that are compatible with jRuby you could give it a try. Don’t do what I saw one commenter doing though which is running ruby on his development machine and then jRuby on production. Real recipe for disaster there.

Just wanted to throw out an update to the article that gets the most attention on my blog.

Posted in Uncategorized | Leave a comment

My 10 Year old picks the Falcons to win the superbowl

My 10 year old son has picked the winner in each of the last 4 super bowls. He doesn’t wait for the game either. Last year he latched onto the Saints in about week 4. I don’t remember when he started rooting in other years, but I do remember him hanging on the Giants as the playoffs started a few years ago and they were a greater long shot than Atlanta.

This year it’s Atlanta. He picked Atlanta in about week 8 or 9. He has been rooting for them ever since. He has them winning over the Ravens.

Things are looking good so far. He rooted for Seattle over New Orleans today and Seattle won. I forgot to ask him about the Colts/Jets before he went to bed, but I will update this post with the rest of his playoff picks tomorrow, so check back in then.

Not much other than bragging rights on the line. He has a few championships t-shirts and some jersey’s from his favorites, but nothing else on the line. Last year he was the only one of us rooting for New Orleans. Both my wife and I are from Indiana and I have been a Colts fan since they moved to Indianapolis.

Posted in Uncategorized | 2 Comments

Freedom of Speech Online

I live in the United States. As such I enjoy an immense amount of freedoms both online and in the real world. I have been doing some research lately into other areas of the world and how people get their message out. It amazes me how hard it is for some people to voice their opinions online. The Global Voices Advocacy group has a guide for anonymously posting online. In places like China or Iran you have to be very careful. In the recent Student Day protests in Iran, a day in which students protest in honor of the killing of student protestors in 1953, students were expelled merely for questioning why other students were expelled. A pretty harse consequence in a country with high unemployment.

So the next time you decide to rant on some topic, either intelligently or unintelligently, remember that it’s the freedoms in the Constitution of the United States that allow you to do so without fear of reprisal. The United States is one of the only countries in the world with that level of freedom. A lot of other countries including many that are considered Democracies don’t have that level of freedom.

So lets all go out and exercise those freedoms.

Posted in Uncategorized | Leave a comment

Validating against LDAP in Ruby on Rails

For work we wanted to have our users login using their Windows domain account. Windows domain servers have an LDAP implementation so we decided to add LDAP support to our AuthLogic login scheme.

The first step is to get a basic LDAP Authentication working. The followings steps detail that method.

First go to https://entic.net/CF and setup an account there. You will receive an email with important connection information.

Install the ruby-ldap gem.

sudo gem install ruby-ldap

Next you should test that you have everything figured out by connecting to your LDAP.

require 'net/ldap'
ldap = Net::LDAP.new
=> #<Net::LDAP:0x100540f78 @open_connection=nil, @encryption=nil, @auth={:method=>:anonymous}, @verbose=false, @port=389, @base="dc=com", @host="127.0.0.1">
ldap.host 'ds1-sjc.entic.net'
ldap.port = 389
ldap.auth 'uid=username, ou=People, o=entic.net', 'pwd'
ldap.bind

If it all works you should get a true response, entering an invalid password will get a false. There are other errors you can get if you have the wrong connection etc.

Once this method works you can try working with the LDAP you are going to connect to for regular use.

Once I had this working I added in the AuthLogic-LDAP. I had to make a lot of modifications though and those can be seen at https://github.com/onyxgs/authlogic_ldap.

To use this you need to add your settings to the UserSession class.

class UserSession < Authlogic::Session::Base
  ldap_port 389
  ldap_host 'ds1-sjc.entic.net'
  ldap_ou 'People'
  ldap_o 'entic.net'
  find_by_ldap_login_method :find_by_username
end

There are also some settings you can/should make in the User class.

  acts_as_authentic do |config|
    config.validate_email_field = false
    config.validate_ldap_login = AppConfig.use_ldap
  end

Posted in Ruby on Rails | 2 Comments

prawnto, prawn and partials

Ran into some interesting gotchas with partials and the prawnto library. Prawn is a powerful low level PDF coding library for ruby. The prawnto plugin creates a template method for generating PDFs using templates and prawn.

I was coding along and wanted to start breaking things down into more manageable pieces but was having trouble with getting the partials to print.

The important thing to note with the partial is you need to pass along the pdf variable. However, you can’t pass it like this:


render :partial => 'coolstuff', :locals => {:pdf => pdf}

That would be the logical way to do it, however, the templating system messes up the use of the pdf variable in the partial. So you must use an alternate variable in the partial.


render :partial => 'coolstuff', :locals => {:p_pdf => pdf}

Posted in Ruby on Rails | Leave a comment

Issue with Nokogiri on Ubuntu 10.04 and JRuby

Switched to JRuby recently and have entered a whole new world of unsupported libraries. While Ruby seems to be quite well supported, getting information on JRuby specific issues is much harder.

The problem I encountered could very well be an issue with Ruby, but seems to be more an issue for JRuby and Nokogiri.

I got the following error:


Could not open library 'xslt'

To fix this I installed two additional packages


sudo apt-get install libxslt-dev libxml2-dev

Posted in Ruby on Rails | Leave a comment

Setup Netbeans on OSX and Oracle OCI8 for Ruby on Rails

I switched over to Netbeans on OSX from TextMate after using Netbeans a lot on my ubuntu setup. First thing I ran into was the following error when I started the application.


oci8lib.c:98:in oci8lib.bundle: OCI Library Initialization Error (OCIError)

The problem is that OSX is starting netbeans from a separate shell than from your usual terminal shell. Netbeans has a configuration file that you can add to put in your environment stuff.

Create a file called netbeans.conf in your ~/.netbeans/6.9/etc folder. You may have to create the folder first. The contents of the netbeans.conf should be the enviornment settings pulled from ~/.bash_profile. An example is below:


export ORACLE_BASE=/Users/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
export ORACLE_SID=<your SID>

Mark the file executable and start netbeans again.

My Configuration:
Unibody MacBook Pro 15″, 2.66 GHz Core2Duo
Oracle 10g
Netbeans 6.9
Ruby 1.7
Rails 2.3.8

Posted in Ruby on Rails, Tools | Leave a comment

Gather Statistics for Oracle

Oralce requires that you periodically gather statistics on the queries you are running. The following command will do that for your local schema. It can be run as the schema owner or sysdba


exec dbms_stats.gather_schema_stats(ownname=> '<schema name, upper case>', cascade => true)

Posted in Uncategorized | Leave a comment

text_field_with_auto_complete pass multiple field values

In ruby on rails there is a method called text_field_with_auto_complete. By default it will call a method on your controller with the name auto_complete_for_<form>_<field>. It will pass in a param value for the field you are updating. The details of this I am not going into here, they are well documented elsewhere.

For this exercise I am going to show how to setup the tag so that you can pass multiple field values.

Example:


<%=  text_field_with_auto_complete :user, 
    :habitat_name, 
    {:class => 'input'}, 
    {:with => "'&user[state]=' + jQuery('#user_state').val() + 
        '&user[habitat_name]=' + jQuery('#user_habitat_name').val()", 
     :skip_style => false} %>

In the example above I am using the jrails plugin to implement jQuery so the syntax is for jQuery. The key clause is the :with class. Here you will need to implement not only the primary field you want to pass, but can add any others you wish. In my case I have a user[:habitat_name] and user[:state]

Posted in Ruby on Rails | Leave a comment