Vita Rara: A Life Uncommon

Mark's [J]Ruby on Rails Notes

Categories: | |

Using GoldSpike to run Ruby on Rails in Standalone Mode

When running Ruby on Rails in a war using the GoldSpike servlets and context-param jruby.standalone is set to true you will need to use the jruby-complete jar file. Rails requires Gems in order to boot strap. I found that using the jruby jar file caused Rails to fail in initializer.rb when it tried to require 'logger' which is included in the ActiveSupport gem.

Also be sure to copy your required gems into WEB-INF/gems.

[EDIT: Better yet use ruby gem install --install-dir WEB-INF/gems. ]

Model Auto Completer

I've rarely used auto completing text fields in the past, because the field I'd autocomplete against wasn't unique. (Use case: Select the party to create a trouble ticket for by name. The names aren't guaranteed to be unique.)

In the past when I've needed to do this in Struts 2 I rolled my own Javascript to manage a hidden id field.

Those do it my own days are over. Take a look at Model Auto Completer for the win.

Some quick notes:

  • This was the first Ajax thing I tried this with in a new project and I forgot to add <%= javascript_include_tag :defaults %> to my layout html.erb file.
  • Model Auto Completer depends on the auto completer plugin. You can get it from github.
  • For some reason the authentication token has issues with it so I added the following to the top of my action: " skip_before_filter :verify_authenticity_token, :only => [:auto_complete_belongs_to_for_kase_party_full_name]"

Favorite Plugins and Gems

  • make_resourceful: DRY up your restful controllers.
  • model_auto_complete: see above.
  • guid: Use globally unique ids with ActiveRecord.
  • ruport: The Ruby Reporting gem. Use this to group and pivot datasets for reporting.
  • RESTful Authentication: add authentication, account creation, etc. to your Rails projects.

RESTful Authentication

Great plugin and pretty much the standard for adding login and authentication to a Rails project.

The README used to have the information about how to secure your controllers, but that seems to have gone missing. Take a look at AuthenenticatedSystem in your lib directory. Include that in some base controller class with a before_filter :login_required as a starter.

Warbler: Easily Packge Rails Apps as a war File for EASY Deployment

Warbler by Nick Sieger is a great tool for packaging a Rails app for deployment as a war file on a Java application server. Quick no nonsense approach.

The only draw back I found was that adding gems to the warbler.rb config file, such as activerecord-jdbc-adapter and jruby-openssl made running my normal Ruby installation's rake fail because I don't have those gems installed for use by my CRuby installation, because the don't work. My quick solution to this was the following:

  config.gems << "activerecord-jdbc-adapter" if defined? JRUBY_VERSION
  config.gems << 'jruby-openssl' if defined? JRUBY_VERSION

The guard simply interrogates the environment to see if we're running in JRuby. If we're not it just ignores those lines. This allows me to keep happily developing in CRuby and deploy on JRuby.