Integrate the Quilljs Editor (WYSIWYG editor) into the Rails application

Tram Ho

Previously in the article The popular WYSIWYG editors for the website I mentioned the Quilljs editor. This is also one of the most popular rich editor recently by the convenient support functions for editing (Including a very nice interface.

One of them is the Bubble interface with the same Editor display as Medium. When you need to format the text, simply highlight and Edior will appear

The integration of Quilljs into the Rails application is also quite easy because there is now Gem supporting developers to do it quickly.You can refer to Gem at the link: https://github.com/abhinavmathur/quilljs -rails

How to install

Add this line to Gemfile

gem 'quilljs-rails'

Then type

$ bundle install

Or type the following command line directly from Terminal

$ gem install quilljs-rails

Using

Insert Script Js and embed CSS Quill into your web from CDN by inserting the following 2 code snippets in the HEADER section in application.html.erb file

Add this line to the application.js file

//= require quill.global

** Note: ** If you do not want to Load js and css words via CDN, you can add the following 2 lines to the application.js file

If you want to turn normal text_filed or text_area into Quill Editor, you just need to add quill_container class to it

For example

<%= f.text_field :title, label: 'Title', type: 'text', class: 'quill_container' %>

Or if you use Simple form , the way to declare is as follows

<%= f.input :title, input_html: { class: 'quill_container' } %>

By default, the settings for Quilljs will be as follows

To be able to customize, you can use the following code.

Quilljs supports 2 themes (interface for editor), snow and bubble. You can use them by requiring corresponding to file application.css (or application.scss if using sass)

*= require quill.snow

*= require quill.bubble

See the Quilljs document for more ways to customize the Toolbar for your Editor: https://quilljs.com/docs/quickstart/

Share the news now

Source : Viblo