Phusion Announces Passenger for Nginx

In the relatively short time since its release, Phusion Passenger has become part of the preferred deployment strategy for many Rails applications. But because it’s targeted at Apache, some sites have been unable to use Passenger. Apache is a great full-featured web server, but for highly traffic nginx seems to consistently deliver better throughput at lower memory use.

As of today, though, the Rails server landscape is changing for the better once again with the announcement of Phusion Passenger for Nginx. This new version takes the Passenger technology, including the use of Ruby Enterprise Edition, and integrates it tightly with nginx. How tightly? Well, you just install the Passenger 2.2.0 gem and run the included nginx installer, and you get a custom-built version of nginx along with instructions on how to configure it to server your Rails site. In addition to combining the benefits of nginx and Passenger, this has the side effect of greatly simplifying the nginx setup.

For more details, including a screencast, hop on over to Phusion’s blog

Rails IDEs March On

Many Rails developers are perfectly happy working on their code in a text editor – and there are certainly plenty of excellent text editors out there. But others, particularly those who have come to Rails from another platform, find themselves wanting a full integrated development environment. For the latter group of developers, there’s good news: two major cross-platform Rails IDEs have releases available now.

Aptana’s RadRails (a plugin for their Aptana Studio IDE) has just released version 1.2. This Eclipse-based environment will seem instantly familiar to many users, and version 1.2 has a couple of major advances to boast about. First, it includes a wizard that will aid new users in setting up Ruby, Gems, and Rails; this is likely to be especially useful to those coming to Rails on Windows. Second, it has built-in deployment to Aptana’s Cloud Connect scalable deployment service, giving a pain-free way to get your Rails applications up and running.

Also worth a look is JetBrains’ RubyMine, currently in late beta prior to its commercial release. A purpose-built Rails IDE, it offers a variety of features including rake support, a model diagrammer, built-in web previews, and code quality tools. RubyMine isn’t finished yet, but the current beta version is showing good promise.

Both RadRails and RubyMine have the features you’d expect from an IDE, including flexible code editors, refactoring support, built-in hooks for test running, integrated debugging, and source code integration. RadRails comes in both community and $99 Pro editions, while RubyMine is scheduled to be released at $99. Whether you prefer to work in a text editor or an IDE, the appearance of these applications is yet another sign of the continuing popularity and growth of the Rails ecosystem.

Rails (and family) on Lighthouse

Lighthouse “version 2” deployed yesterday, so I’m officially opening the Rails Lighthouse tracker up for business. Other spinoff projects such as Prototype and Capistrano have already made the switch. As David has mentioned, this means the current trac instance is deprecated. It will continue to stay in use for now until everyone has transitioned to Lighthouse.

We’re still figuring out the new workflow with git, Github, and Lighthouse. I’ll be working with the Logical Awesome folks to improve the Lighthouse/Github relationship. I’m also working with Tim Pope (author of the awesome git-trac tool) and others in #rails-contrib on bringing the same development tools to the new git infrastructure. Tim also wrote some best practices for contributing to Rails from git.

Rails tool space is heating up

There’s a lot of action going on in the Rails IDE space these days. Besides Aptana RadRails, which has been around for a long time, Sun’s got impressive Rails support in the new NetBeans, and just this week CodeGear launched their 3rdRail IDE, which also looks like a great setup.

I’m personally not quite ready to leave TextMate behind, but it’s encouraging to see all these options for dedicated Rails IDEs. It’s not going to be long before they’ll be giving regular text editors a serious run for their money.

IntelliJ jumps on Ruby and Rails

JetBrains’ IntelliJ has long been the gold standard for Java IDEs. Now the company is taking a shot at turning their suite into a good fit for Ruby and Rails development. This new love is coming in the form of a new official Ruby plug-in.

It features assisted Ruby coding, with keyword completion, syntax highlighting, on-the-fly code validation, error highlighting, and Rails templates and generator integration. They even put together a screencast to show it off.

Cool stuff. Especially if you already plugged down $400 for a license or work on an open-source project (free license, then).

In case you're having trouble installing gems...

A significant number of Rails developers have reported problems installing gems with the updated RubyGems release. If you’re experiencing a problem that looks anything like this:

$ gem update sqlite3-ruby Updating installed gems… ERROR: While executing gem … (NoMethodError) undefined method `refresh’ for #

…you should remove your local source_cache file. This is the file that locally caches any gem metadata from the gem server to avoid having to re-download it every time you execute a gem command.

To discover the location of this file on your system, run the following command:

$ gem env RubyGems Environment: - VERSION: 0.9.2 (0.9.2) - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8 - GEM PATH: - /usr/local/lib/ruby/gems/1.8 - REMOTE SOURCES: - http://gems.rubyforge.org

The source_cache file should be in the path labeled by GEM PATH. Removing that file should clear up any related issues.

This solution is a workaround pending a fix by the RubyGems team.

Unobtrusive Javascript Plugin

Dan Webb and Luke Redpath have release the latest version of their Unobtrusive Javascript Plugin for Rails. It solves several of the main problems people run into when working with unobtrusive javascript:

  • Development isn’t as intuitive with Rails when you’re defining your custom javascript behaviors in an external file.
  • When working with pages with lots of images and content, the behaviors won’t be enabled until everything is downloaded and window.onload is called. It’s been solved with some nasty cross-browser javascript hacks, all handled transparently by Dan’s LowPro extension for prototype. This has been a big deal for me personally, so it’s nice to see it all solved.

UJS attempts to solve this by taking defined behaviors in the view and creating a tailored javascript file for it. Smart conditional GET and page caching techniques can be used to save bandwidth and time.

All in all, it looks like Dan and Luke did an excellent job on the plugin. Anyone using it? How’s it working out for everyone?

Remember CRC Cards?

In 1988, Ward Cunningham (yes, that Ward Cunningham) came up with an idea to use index cards as a tool for object-oriented design. I was working for Kent Beck at Apple at the time, so I got to hear Ward describe his idea over speakerphone in Kent's office. Ward and Kent presented a paper on CRC cards at the OOPSLA conference the next year, and suddenly they were all the rage. Some companies even printed up branded CRC cards, which still makes me laugh.

Take an index card. (3x5 or 4x6 are good sizes, but any larger than that and they become too unwieldy to move around.) Write the name of a class across the top. Draw a vertical line separating the rest of the card into uneven halves - the left half should take up about 2/3 of the width. On the left side write the responsibilities of the class. On the right side write the objects or classes of objects that objects of this class collaborate with. That's the basics right there. Once you have cards representing several classes, you can arrange the cards to explore object interactions and discover new responsibilities and collaborations.

While CRC cards can be used solo, where they really shine are during collaborative design. It's easy for one person to move a card around to show others what they mean. Since cards move independently, two people can be writing on different cards at the same time. It makes for a lightweight yet effective group design process. It's also a decent way to describe a design.

CRC cards also play well with the Rails mindset where constraints are empowering. Cards are small, so you can't write so much on them that they become too complex to understand. Limited space keeps you focused on the important stuff. And since cards are easy to make, they are also easy to throw away - no investment equals no pain. Don't like what's on a card? Just tear it up and start over.

A good way to start with CRC cards is to use them to document an existing design. That way you don't have to deal with creating a design while learning a new tool at the same time. Then you might use them to modify or expand the design for existing software. Once you are warmed up with them you can take them for a spin on a brand new design.

My brief explanation hardly does the topic justice. Read Ward and Kent's paper, explore the original wiki for CRC card articles, and of course google around for yet more information.

Dan Webb's Request Routing Plugin

Have you ever wanted to write Rails routes using a URL's subdomain? What about routing based on whether a request was HTTP vs HTTPS? Well, now you can. Recently Dan Webb released his "Request Routing Plugin":http://svn.vivabit.net/external/rubylibs/requestrouting/README for public use. This plugin lets you create routing rules that use a whole slew of new properties: domain, subdomain, method, port, remoteip, contenttype, accepts, requesturi, and protocol.

You can obtain the plugin from Dan's subversion repository:

ruby script/plugin install \
   http://svn.vivabit.net/external/rubylibs/request_routing/

New in Rails: Module#alias_method_chain

Though not an outward facing feature, changeset 4276 introduces a nice method to DRY up and encapsulate the common pattern of aliasing a method so that you can build behavior on top of it.

All over the internals of Rails you’ll find code like this in a module:


  module Layout #:nodoc:
    def self.included(base)
      base.extend(ClassMethods)
      base.class_eval do
        alias_method :render_with_no_layout, :render
        alias_method :render, :render_with_a_layout

  1. … etc

This makes it so that when the module is included into the base class, it adds behavior onto some method in that class without the method having to be aware of the fact that it’s being enhanced. In this case, the render method of ActionController::Base is enhanced to wrap its output in a layout.

The new Module#alias_method_chain wraps up this pattern into a single method call. The above example, once refactored to use Module#alias_method_chain, would simply be:


alias_method_chain :render, :layout

This will be used to refactor quite a bit of Rails internals which may not be of immediate relevance to what you do, but it serves as a nice example of the mechanisms Ruby provides for software organization. Small victories.

Stress testing your protected pages

David came up with a quick tip for anyone stress testing protected pages with a stateless tester, such as siege.

  1. Log in with your browser
  2. View the cookies and find the session id (Firefox has a handy cookie search tool)
  3. Prepend the queries with ?_session_id=YOURSESSIONID

Now, any requests made will be as though they came from your account.

Do you have any other handy tips for stress testing your Rails applications?

Plug into HyperEstraier with acts_as_searchable

Patrick Lenz has announced his acts_as_searchable plugin which integrates ActiveRecord models with HyperEstraier, an open source fulltext search engine.

It’s available as a gem so you can just do sudo gem install acts_as_searchable.

You can then take a look at the API docs, which provide a few examples.

Full text searching just got as simple as:


class Article < ActiveRecord::Base
acts_as_searchable
end

Article.fulltext_search(‘biscuits AND gravy’)

Quick PDF generation with RTex

Bruce Williams of Naviance recently announced his RTex plugin. It exposes your controller data to rtex views that output LaTeX which is convereted to PDF.

To install you can use the plugin script:

ruby script/plugin install rtex

Or grab it from svn:

svn co http://codefluency.com/svn/codefluency/rails/plugins/rtex

People have used PDF::Writer to generated .rpdf views. Why go through LaTex to get to PDF rather than use PDF::Writer? Speed, says Bruce.

Auto sanitized templates with Erubis

Last month on the Rails core mailing list, a thread popped up (that went on and on) wherein the idea was proposed that rhtml templates should automatically sanitize output by default. After much back and forth, David suggested those in favor redirect their energies toward a working plugin.

Enter stage left, Erubis. It’s a customized implementation of eRuby that provides a handful of features, notably that <%= %> tags automatically sanitize output. You use <%== %> if you don’t want to sanitize the output. For all those who wish rhtml files were sanitized by default, here is your solution.

Configure your Rails apps to use Erubis templates with ActionView::Base::register_template_handler.

Fast Rake Task Completion for Zsh

Those of you who love running Rake tasks but don’t like typing are in for a treat. Although there’s been task completion for Rake for a while now, most of the scripts for it are painfully slow, especially with Rails’ Rakefile.

Below is a small zsh completion script that uses a cache file (named .rake_tasks) to improve the performance of your tab keystrokes.

To use, throw it in your home folder somewhere and add source $HOME/.rake_completion.zsh to your .zshrc file.

A few disclaimers: Yes, it doesn’t work with lowercase named rakefile‘s. Only barbarians use such names though, so hopefully you won’t have a problem there. And no, it doesn’t complete the other assorted arguments that the rake command can accept, frankly because I rarely use them.

Without further ado, here’s the bytes.

_rake_does_task_list_need_generating () {
  if [ ! -f .rake_tasks ]; then return 0;
  else
    accurate=$(stat -f%m .rake_tasks)
    changed=$(stat -f%m Rakefile)
    return $(expr $accurate '>=' $changed)
  fi
}

_rake () {
  if [ -f Rakefile ]; then
    if _rake_does_task_list_need_generating; then
      echo "\nGenerating .rake_tasks..." > /dev/stderr
      rake --silent --tasks | cut -d " " -f 2 > .rake_tasks
    fi
    compadd `cat .rake_tasks`
  fi
}

compdef _rake rake

(Use at your own risk. Comments and improvements welcome.)

Capistrano 1.1

Capistrano is a utility for executing tasks in parallel across multiple remote hosts. It was formerly known as SwitchTower.

Installation:

gem install capistrano

Version 1.1 introduces a few changes:

  • The generated capistrano.rake file is simpler now than it used to be. You can easily append custom options to individual tasks now. For instance, if you want the deploy to be silent, instead of verbose, just add “-q” to the parameter list for that task.
  • The generated capistrano.rake file uses the “remote” namespace, so you’ll need to have at least Rake 0.7.0. You can still do “rake deploy” and “rake rollback”, but the other tasks must be prefixed with the namespace (“rake remote:exec”, “rake remote:show_tasks”, etc.)
  • The ‘switchtower’ command is replaced by the ‘cap’ command.
  • The cap utility is verbose by default. If you want it to be silent, use the -q option. If you want it to be less verbose, you can specify the -v or -vv flags explicitly.
  • The cap utility uses more rake-like command-line semantics. Instead of needing to do “cap -r config/deploy -a deploy”, you can just do “cap deploy”. It will look for config/deploy.rb, capfile, or Capfile automatically, and will treat raw parameters as action names.

Upgrading/switching from SwitchTower to Capistrano is a little inconvenient. Here’s what you’ll need to do:

  • gem uninstall switchtower (remove all versions)
  • gem install capistrano
  • For each of your Rails projects, do “cap -A .”, keeping your deploy.rb
  • For each of your Rails projects, remove lib/tasks/switchtower.rake

Enjoy!

SwitchTower is now Capistrano

We were served with a “cease and desist” from Raindance Communications, Inc. over the use of their registered trademark SWITCHTOWER on Friday. This led to a wild three-day brainstorming session and a new name for SwitchTower: Capistrano.

New gems and so forth will be available tomorrow, as well as updated documentation using the new name. For existing SwitchTower users, you’ll need to run cap -A . on each of your projects, once the new gems are available and installed. (cap is the new name of the switchtower utility.)

You can read all about the brainstorming process and how the new name was selected on Jamis’ blog.

Sneak peak at effortless deployment with Rails Machine

SwitchTower author Jamis Buck has provided an excellent manual documenting how to use it. Those who’ve taken the plunge are loving how easy it makes deployment, as well as myriad other tasks. But I’m still always hearing, “We haven’t setup SwitchTower yet but are really looking forward to”.

Enter Rails Machine. It sets out to lower the barrier to using SwitchTower by taking care of all the setup and maintenance. They are scheduling to open their doors in April. For now take a look at the short movie they’ve made showing how easy they’ve made it for you to get going with SwitchTower. They get you up and running in under 5 minutes. No more excuse to not realize how much you love SwitchTower.

Rake 0.7.0 has been released

Rake 0.7.0 has taken a great leap forward with the addition of parallel execution tasks and namespaces. Upcoming releases of Rails will surely use namespaces, so please do familiarize yourself with them today. And many thanks to Jim Weirich for his continued stellar work on this.

Caching models with memcached

The Robot Co-op has released their memcache-client and a plugin for Active Record that uses it. This enables you to cache your models in the distributed memory cache and not hit your database for repeat visits all the time. They use this to power 43things and the rest of their social suite.

SwitchTower with Bazaar-NG

Damien Merenne has just announced a Bazaar-NG SCM module for SwitchTower. All you bzr users now have one less reason to not use SwitchTower.

Damien has given permission for this module to be included in the next SwitchTower release, too. If you’ve got a pet SCM that you’d like to see supported by SwitchTower, just take a look at Damien’s code to see how little it really takes to implement a new SCM module. Then, implement it and submit it as a patch to http://dev.rubyonrails.org/newticket.

SwitchTower with Perforce

Richard McMahon has written about using Perforce as the SCM with SwitchTower (here). He’s even written a custom Perforce SCM module for SwitchTower, so if you’re a Perforce user wanting to dabble with SwitchTower, it looks like you’re in luck.

(Richard has given his permission for the Perforce SCM module to be included with the next SwitchTower release.)

TextMate v1.5 released

TextMate is the editor powering the work of every single core contributor and now the best just got even better. The 1.5 release of TextMate is the first official in a long time. So if you last had a look at 1.0.2, it’s time to take another peak.

Oh, and if you haven’t switched yet, you can swing by Apple and pickup a Mac on the way to TextMate. It’s not now, nor ever, going Windows.

SwitchTower as an Automated Deployment Archetype

Mike Clark has written a provocative article entitled SwitchTower as an Automated Deployment Archetype in which he suggests that developers of all stripes ought to consider SwitchTower for their deployment system, whether or not they are using Ruby on Rails. I know I’ve heard at least one story of someone using SwitchTower to manage a PHP application. Anyone care to share any other success stories of SwitchTower managing a non-Rails application? Any gotchas potential users might want to be aware of?

Komodo 3.5: IDE with support for Ruby on Rails

RadRails is getting company from commercial player ActiveState that has recently shipped Komodo 3.5, their IDE for dynamic languages. Komodo features support for Ruby and Rails and is available on Windows, Linux, and Mac OS X.

Komodo Professional is a $295 buy, Komodo personal is $29.95, and there’s a 21-day trial available.

The release got a bit of play in the press with an InfoWorld article called Ruby IDE is set to shine.

Being a OS X/TextMate user myself, I haven’t had a chance to checkout Komodo. Please do add your experiences in the comments for others to share.