Quantcast
Channel: 4 Lines of Code » ruby
Viewing all articles
Browse latest Browse all 15

CKEditor and Rails

$
0
0

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?


Filed under: javascript, ruby, rubyonrails

Viewing all articles
Browse latest Browse all 15

Latest Images

Trending Articles



Latest Images