DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Adding Spellchecker To TinyMCE Rails Plugin

09.17.2009
| 1441 views |
  • submit to reddit
        Add the spellechecker plugin to TinyMCE using Aspell

1) Install Aspell:

sudo apt-get install aspell

2) Make sure the english dictionary is installed with 

aspell dicts

3) Add 'spellchecker' to the ':options => :plugins' array of users_tiny_mce in the controller.

4) add the following to the ':options' hash:

:spellchecker_languages => "+English=en",

:spellchecker_rpc_url   => '/spellchecker'

5) Set ':theme => :advanced' and make sure 'spellchecker' is in one of the ':theme_advanced_buttons_[1|2|3|4]' strings

6) Set up the route in config/routes.rb:

map.spellcheck '/spellchecker', :controller => 'admin/dashboard', :action => 'spellchecker'

7) Add the spellchecker action to the controller:

class Admin::DashboardController < ApplicationController

  include TinyMCE::SpellChecker

  def spellchecker
    language, words, method = params[:params][0], params[:params][1], params[:method] unless params[:params].blank?
    return render :nothing => true if language.blank? || words.blank? || method.blank?
    headers["Content-Type"] = "text/plain"
    headers["charset"]      = "utf-8"
    suggestions             = check_spelling(words, method, language)
    results                 = {"id" => nil, "result" => suggestions, "error" => nil}
    render :json => results
  end

end