Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Treat any ActiveRecord's string field as a dictionary to do word suggesting & spelling checking using Hunspell
branch: master

This branch is even with tiendung:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
tasks
test
MIT-LICENSE
README
Rakefile
init.rb

README

ActsAsDictionary
================

ActsAsDictionary creates Hunspell (http://hunspell.sourceforge.net/) dictionaries using data from ActiveRecord models and provides class methods to access these dictionaries.

Pre-requisites
==============

This plugin requires the Hunspell library and RubyInline gem.

To install Hunspell:
	
	curl -O http://nchc.dl.sourceforge.net/sourceforge/hunspell/hunspell-1.2.7.tar.gz
	tar -zxvf hunspell-1.2.7.tar.gz
	cd hunspell-1.2.7
	./configure
	make
	sudo make install
	
To install RubyInline:

	gem install RubyInline
		
Setup
=====

Within a model, define the column you want to work with:

	class Klass < ActiveRecord::Base
	  acts_as_dictionary :checks => :name
	end

Or, if you want to create dictionaries using two or more columns

	class Klass < ActiveRecord::Base
	  acts_as_dictionary :checks => [:name, :type]
	end

Once done, you can proceed to generate basic Hunspell dictionary files with:

	rake dict:generate

In the above example, the following files will be generated:

	#{Rails.root}/dict/klass_names.aff
	#{Rails.root}/dict/klass_names.dic
	#{Rails.root}/dict/klass_types.aff
	#{Rails.root}/dict/klass_types.dic
	
Each pair of these files (*.aff and *.dic) are Hunspell dictionary definition files	which you can further configure if needed (see http://sourceforge.net/docman/display_doc.php?docid=29374&group_id=143754).

Note that if manually configure the files, running the dict:generate Rake task again will override your manual configurations.

Usage
=====

With this plugin, the following dynamic class methods are available (replace * with a column name you have specified to check):

	>> Klass.find_by_*_with_spell_check("Naem")
	=> #<Klass id: 1, name: "Name">
	
	>> Klass.suggest_*("Naem")
	=> ["Name", "Name2"]
	
	>> Klass.check_*("Name")
	=> true
Something went wrong with that request. Please try again.