Thierry M.
Thierry M.

Reputation: 113

Rails 4: Simple Rich Text Editor (currently using text area)

I am currently using a f.text_area for users to enter text inside a form. Since those entries can be quite long, I want to offer my users to format the input with bold, italic and underlines.

Ideally, users access the formatting options with the common cmd+b, cmd+i and cmd+u.

I know about contenteditable but since this can't be applied to a textarea inside a form but only to a div, this does not seem to work inside a rails form.

What other options are there that play nicely with form_for?

Upvotes: 2

Views: 1400

Answers (2)

Richard Peck
Richard Peck

Reputation: 76774

We've implemented CKEditor before - here's how to do it (I can delete if you wish):

#Gemfile
gem 'ckeditor', '~> 4.1.6'

#app/assets/javascripts/application.js
//= require ckeditor/init

#config/initializers/asset.rb
Rails.application.config.assets.precompile += %w(ckeditor/*)

#app/assets/javascripts/ckeditor/config.js
CKEDITOR.editorConfig = function(config) {
  ...
};

The beauty of this gem is it integrates with Paperclip, allowing you to upload files directly to the server (I can provide code if required).

You can also change the toolbar & styling to be anything you like.

Although it's quite bloated, it's the best we've used. The other good one you'll benefit from is redactor, although it's premium and I've not seen a direct integration into Rails.

Upvotes: 1

Philipp Meissner
Philipp Meissner

Reputation: 5482

Ruby on Rails Solutions

  1. rails-ckeditor
  2. Mercury
  3. rails_tiny_mce
  4. redactor-rails

I personally suggest Mercury, there's also a Railscast available for this specific gem :)

I hope this helps!

Upvotes: 3

Related Questions