Sometime back I added the final ruby 1.9.2 build for Ubuntu Lucid. I have recompiled the same for Maverick today and have uploaded it to the ppa. Along with the ruby1.9.2 packages I have uploaded the ruby-default package too. This setups the update-alternatives system for different ruby versions. Read more about it here.Continue reading

This has been long overdue. I just updated my ruby 1.9.2 ppa to the final ruby 1.9.2 release. I borrowed the patches from the upstream maverick release and added a couple more patches to get it work on Ubuntu Lucid. The patching system has now changed from dpatch to quilt. Please download it and enjoy it and let me know if things work fine. I checked my rails applications and they all are working fine with the new release. Here are the instructions to use the Ruby 1.9.2 PPA.Continue reading

RAILS_ENV returns an empty value in custom rake tasks rails 3.0.0.rc onwards. Instead use Rails.env.

Example Usage:

Lets say you want to determine if you are running the development environment then you could use the following method.

desc "Raise an error unless the RAILS_ENV is development"
task :development_environment_only do
  raise "Hey, development only you monkey!" unless RAILS_ENV == 'development'

Now to ensure your custom method is running in development environment, call the development_environment_only method as a dependency of your rake custom task.

task :abc => [:environment, :development_environment_only] do

If you wish to pass arguments to your rake task, then the code to call the dependencies would be:

task :abc, :argument, :needs => [:environment, :development_environment_only] do |t, args|

Lets say you have a form with the following checkboxes.

<%= f.check_box :checkbox1 %>
<%= f.check_box :checkbox2 %>
<%= f.check_box :checkbox3 %>

Now to make sure atleast one checkbox is checked, add the following code to your model.

  validate :atleast_one_is_checked

  def atleast_one_is_checked
    errors.add(:base, "Select atleast one output format type") unless checkbox1 || checkbox2 || checkbox3

The trick to choose multiple layouts for the same controller is to define the layout as a method and then choose the layout depending on the action_name. Here’s the sample code for a controller which uses the layout site-index for the action index and the layout site for rest of the actions.

class SiteController < ApplicationController
  def index
  def about

  def help
  layout :choose_layout
  def choose_layout
    if action_name == 'index'
      return 'site-index'
      return 'site'

I have started working on a webapp on Heroku. Heroku requires you to specify where your external gems come from. This is nice as you can specify a RubyForge, RubyGems, GitHub or any repository for that matter. However RubyGems is the de-facto gem host these days. All the gems on RubyGems have owners/co-owners and only they can update/upgrade the gem. Now what happens if you have a lazy gem owner who hasn’t updated the gem for over 2 years? You get an outdated gem. The only option is to update the gem yourself and host it elsewhere. Thats what made me create my custom gem server on Dreamhost.Continue reading

I have started working on a Ruby on Rails project and am using Rails 3.0 as the base version. Rails 3.0 can be installed either with Ruby 1.8.7 or Ruby 1.9.1. I decided to go along with 1.9.1. However I soon found out that a lot of ruby-bindings have not been updated to support Ruby 1.9.1. I did not want a system with both Ruby 1.8.7 and Ruby 1.9.1 versions. Continue reading