add gud spelning to ur railz app or wharever

I cleaned up the raspell gem a little bit and put it on Rubyforge. It’s a Ruby interface to the GNU Aspell spellcheck library:


Mac people:

sudo port install aspell aspell-dict-en

Or, Ubuntu people:

sudo apt-get install aspell libaspell-dev aspell-en


sudo gem install raspell

Of course you shouldn’t install the gem without trusting me and/or auditing the source code, and also making sure your DNS isn’t poisoned with regard to the Rubyforge mirrors, and that the Rubyforge mirrors themselves haven’t been hacked.



The above spell.rb file for your app:

require 'rubygems'
require 'raspell'

module Spell
  SP ="en")
  SP.suggestion_mode = Aspell::NORMAL
  SP.set_option("ignore-case", "false")

  def self.correct string
     string.gsub(/[\w\']+/) do |word|
       not SP.check(word) and SP.suggest(word).first or word


If you just need a “did you mean X” method, this is a great start. Of course sometimes Aspell gets it wrong. However, there are lots of options you can set, and different ways you can report the word possibilities, so you might be able to tune it to your specific situation.

Aspell supports custom wordlists and custom stemming and all kinds of cool stuff. Check the gem’s README and Aspell’s manual for more details.

5 responses

  1. Likewise, Kent, today I had some troubles installing it on RHEL because the aspell.h header from /opt/aspell/include wasn’t getting picked up.

    To anyone else having trouble, remember that for any extension gem, you can run the gem install and then cd to the gem’s /ext directory and handhold the make process to get everything built.

  2. Wow, this looks just like the thing I need for Instiki.

    Too bad that my RoR skills still suck.

    Any chance that I could get you to create a lil’ howto on integrating this with Instiki?

  3. I’ve never used Instiki… it shouldn’t be too hard to integrate, though. I would recommend hiring someone if you are not comfortable doing it yourself.