awesomeprogrammer.com

Sharing ideas

Solving problems

Gathering solutions

Exchanging thoughts

Ruby On Rails

PHP

Postgres

Debian & Ubuntu
jQuery & CSS

Hook Up Aspell Dictionary Into Your Rails App

How to check spelling in your rails app in three quick steps.

1. Install aspell (d’oh)

with desired dictionary/ies.

Ubuntu/debian
1
sudo apt-get install aspell aspell-en aspell-pl

2. Install ffi-aspell

(I can’t recommend respell as it’s quite dated and you probably will encounter some annoying utf-8 encoding problems)

3. Wake up

your inner grammar-nazi!

1
2
3
4
5
6
7
8
  speller = FFI::Aspell::Speller.new('en', encoding: 'utf-8')
  # you may be also interested in those two options for starter:
  # speller.set('ignore-case', 'true')
  # speller.suggestion_mode = 'normal'

  "I have no ideaz wut's goign on".gsub(/[\w\']+/) do |word|
    puts "'#{word}' seems incorrect, did you mean: '#{speller.suggestions(word).first}'?" unless speller.correct?(word)
  end
1
2
3
ideaz' seems incorrect, did you mean: 'ideas'?
'wut's' seems incorrect, did you mean: 'Wit's'?
'goign' seems incorrect, did you mean: 'going'?

It’s a nice feature that you can use eg. for suggesting/validating user’s search queries.

Comments