open_exception gem: now with better emacs support!

I just released v0.3.1 of the open_exception gem. This release does a better job of handling exceptions that have been munged by Rails, and now provides a tempfile containing the full stack trace to the open command.

If you are using emacs, you can use the :emacs_with_trace open command, and get the stack trace as a navigable compilation buffer (next to || below) the source file in a split frame. For this to work, you’ll need to add the following function to your emacs init:

See github for the code and README.

Generate a migration and open it in a buffer (in Emacs)



Requires rinari

Emacs tip: running ack in the project root w/rinari

This post covers how to combine the awesomeness of ack with rinari in emacs to run ack in the project root by default. (If you aren’t using ack, definitely check it out for searching your codebase. If you aren’t using emacs, this post isn’t going to convince you to switch).

I’ve been using Kim van Wyk’s ack.el for a few months now, but was annoyed that I had to tell it the directory where to run ack, when in most cases I wanted it to run in the root of my Rails app. So I copied the ack function from ack.el and made one that only asks for the search pattern, then runs in the root of the app (provided by rinari’s rinari-root function). I then bound that function to C-c f a.

Here is the code:

Note: you will need rinari and ack.el loaded, and ack will need to be in your path.

Refreshing an individual gemspec

I’m in the process of upgrading a rails app from 2.1 to 2.3, and 2.3 wants me to refresh some of the gemspecs for my vendored gems. Unfortunately, when I run rake gems:refresh_specs I get the dreaded:

rake aborted!
can't activate , already activated json-1.1.9

I was able to refresh the spec in question outside of rake with (in the console):

>> Rails::GemDependency.from_directory_name('vendor/gems/gem_name-0.1.0', false).refresh

Hopefully that helps someone else out.

rails_habitat: a simple rails plugin to make RAILS_ENV a bit friendlier

I just released a stupid simple plugin based on the idea behind Coda Hale’s rails_environments plugin.

This plugin adds the following functionality to the Rails module to help with determining the current enviroment:

>> Rails.environment       # a convenience alias to Rails.env
=> "development"
>> Rails.development?
=> true
>> Rails.not_development?
=> false
>> Rails.production?
=> false
>> Rails.not_production?
=> true
>> Rails.test?
=> false
>> Rails.not_test?
=> true

Not only does it provide env? and not_env? methods for the standard environments, it also provides those methods for any environment you define in config/environments/ (in fact that is how it learns about all of the environments, including the standard three). So if you define new environments in config/environments/ they will be picked up automatically.

Install with: script/plugin install git://github.com/tobias/rails_habitat.git

It lives on github.

Edit: see David’s comment below for the built in way to do this (in Rails >= 2.2).