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?
for some reason the JavaScript doesn’t work. Can you elaborate more. My Text area remained the same.
Thank you for this post, it helped me get started and Ckeditor is now working on my rails app. Just wanted to note that I did have to manually add :class => ‘ckeditor’ to my textarea, as the jquery snippet didn’t seem to do the trick for me to dynamically add it either.
Where are we supposed to write those codes..
The javascript include tag would go in your view (or layout ..ie to make it available on every page put it in the head section of app/views/layouts/application.html.erb).
The rest can go in your application.js.
If you still don’t understand I suggest you get the Agile Development with Rails book and read it through. Because it’s going to be hard to get very far without a foundation of understanding.
You really need to make it clear that the above example assumes that jQuery is being used.
Reblogged this on Ganesh Kunwar's and commented:
CKEditor and Rails
My installation was not working until I gave a name attribute to the textarea tag.