November 10th, 2008

Set RAILS_ENV for Phusion Passenger on Dreamhost

Recently I began looking into using Phusion Passenger for running all my Rails apps instead of the normal nginx+mongrel stack that I normally use. Since its release, Passenger has been getting quite a bit of publicity and hype and I figured it was time I started looking into it on my own as well.

Dreamhost was the first shared hosting provider to offer Passenger on all their shared hosting plans so that was a natural place for me to start. I planned on using my Dreamhost box as a staging server for a few small apps as I started to get a feel for Passenger.

The major problem I ran into was trying to set RAILS_ENV to “staging” so that my apps would run from the staging environment. The way Passenger gets configured, the RAILS_ENV setting is configured in the Apache virtual host file, which I don’t have access to on Dreamhost (or most other shared hosting providers).

You can set the RAILS_ENV constant in your config/environment.rb file to ‘staging’ and Passenger will pick the setting up; but, of course, this won’t work because then I would be required to constantly manage and change my environment.rb file depending on whether or not I was working locally in ‘development’ or on ‘production.’

What I decided to do was just add a custom task to my capistrano deployment recipe file (config/deploy.rb) and manually insert the RAILS_ENV variable into the top of my config/environment.rb file after deploy.

namespace :deploy do
  desc "set ENV['RAILS_ENV'] for mod_rails (phusion passenger)"
  task :set_rails_env do
    tmp = "#{current_release}/tmp/environment.rb"
    final = "#{current_release}/config/environment.rb"
    run <<-CMD
      echo 'RAILS_ENV = "#{rails_env}"' > #{tmp};
      cat #{final} >> #{tmp} && mv #{tmp} #{final};

after "deploy:finalize_update", "deploy:set_rails_env"

Now based on my cap deployment command, the RAILS_ENV will be set to ‘staging’ or ‘production’ automatically. Really, staging is all that I needed since production is the natural environment on my production server already.

Hope this helps and saves someone else an hour of searching.

August 21st, 2008

ParseHTML 1.12 Released

I’ve updated the ParseHTML code on github to the latest 1.12 version.

I haven’t done much work with the ParseHTML library, simply because I wasn’t actively doing development on the ClothBlue HTML-to-Markdown library. ClothBlue is the reason I wrote ParseHTML in the first place. Well, I’ve had some downtime and figured I would revive the ClothBlue rewrite effort and that meant getting ParseHTML up to snuff.

The library should be fully working now as most of the previously reported bugs have been sorted out. If you find any issues or new features you want added, just let me know.

August 3rd, 2008

My bash history

$ history 1000 | \
awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | \
sort -rn | head

123 git
80 ruby
71 gs
43 cls
20 git-wtf
18 ll
17 rake
17 gba
16 cd
12 vim

I guess you can say I took the git plunge whole-heartedly. The gs, gba, and git-wtf commands are all git aliases or scripts (git status, git branch -a, and a git branch commit analyzer).

July 31st, 2008

Rails 2.x In Place Editor

I had the need to use the old in_place_editor functionality in a new Rails app that I’m working on. I hadn’t used the functionality for a while now and using it in a Rails 2.x environment is a bit different than in a Rails 1.x environment so I thought I’d share what I found.

The in_place_editor functionality has been completed deprecated in the Rails 2.x codebase and now you need to install the plugin to use the functionality. To install the plugin use the following command from your rails root directory:

ruby script/plugin install

Now, if you are using the new authenticity token features of Rails 2, the plugin won’t work for you out of the box. First you will need to apply this patch. It’s best to apply the patch even if you aren’t using the authenticity token feature just so you are “future-proof.” I’m not sure why the plugin trunk hasn’t been updated with the patch already, but it hasn’t so you need to do it yourself.

Now you can use both the in_place_editor and in_place_editor_field helpers in your view files.

July 23rd, 2008

Learn a (New) Programming Language


I came across an article on Michael Minella’s blog the other day about continually adding new tools to the programming tool box. Specifically, Michael references on of the tenets of the Pragmatic Programmer to learn at least one new programming language every year.

That got me thinking and challenged me to pick up another language this year. I’ve been doing Ruby development exclusively for close to three years now and have really let my PHP level of expertise slide a bit. Other than a bit of JavaScript and some PHP for WordPress plugins and themes, Ruby is all of done recently.

The language that I really want to learn and get into is Objective-C, mostly because I’d like to dabble a bit in Cocoa development for OS X. It’s been quite a few years since I’ve done any kind of desktop app development and I’d like to at least stay up-to-date in that world.

Ultimately though, I decided to really learn Perl this year. Now, I know a bit of Perl and have written some of it in the past, but I really am not as strong with Perl as I’d like to be and I think its probably one of the best languages to really have a good grasp on. Considering that the year is already halfway over, it helps to pick a language that I am already a bit familiar with as well.

So, what language(s) are you learning this year to stay sharp?

© 2019 Craig P Jolicoeur.