CKEditor, the successor of FCKeditor, is one of the most used WYSIWYG text editors, besides the WMD editor which is for instance used in an updated version at Stackoverflow. Integrating the CKEditor in Ruby on Rails is simple. It only requires a few lines of code. There are a number of Rails plugins, but you don’t really need them. Download the CKEditor Zip file, extract the files and place them in the sub directory “javascripts/ckeditor”, add the main JS file to the layout..

javascript_include_tag 'ckeditor/ckeditor.js'

..and write a bit JavaScript code which replaces textareas by CKEditor instances:


  $(document).ready(function() {
     if ($('textarea').length > 0) {       
       var data = $('textarea');
       $.each(data, function(i) {
         CKEDITOR.replace(data[i].id);
       });     
     }  
  });

That’s all! Quite simple, isn’t it?

Advertisements