Using the TinyMCE package with the Ruby on Rails framework
| This Integration is maintained by a third-party developer. Tiny Technologies, Inc. bears no responsibility for this integration, which is not covered by the Tiny Self-Hosted Software License Agreement. For issues related to the integration, contact the third-party project directly. |
Sam Pohlenz maintains the TinyMCE Ruby on Rails gem for integrating TinyMCE into the Ruby on Rails asset pipeline. This procedure creates a basic Ruby on Rails application containing a TinyMCE editor based on our Basic example.
Procedure
On a command line or command prompt:
-
Create a new Ruby on Rails project.
rails new myTinySite -
Navigate into the project directory.
cd myTinySite/ -
Create a new Rails controller, such as:
rails generate controller Welcome indexThis creates a controller named
Welcomewith an action namedindex. -
Set the project home page to
index.-
Using a text editor, open
config/routes.rb, such as:nano config/routes.rb -
Add
root 'welcome#index'to setindexas the project home page. For example:Rails.application.routes.draw do get 'welcome/index' root 'welcome#index' end
-
-
Using a text editor, open the project
Gemfileand add the line:gem 'tinymce-rails'Do not add this line within a
group-endelement. -
Install the
tinymce-railsgem usingbundle:bundle install -
Create a TinyMCE configuration file.
-
Create the
config/tinymce.ymlfile:touch config/tinymce.yml -
Add a TinyMCE configuration. The configuration must be in the YAML format, such as:
height: 500 menubar: false toolbar: - undo redo | blocks | bold italic | alignleft aligncenter alignright | bullist numlist outdent indent | removeformat | help plugins: - insertdatetime lists media table code help wordcount
-
-
Add the following lines within the
<head>element ofapp/views/layouts/application.html.erbto automatically include TinyMCE on pages using theapplicationlayout:<%= tinymce_assets %> <script type="text/javascript" src="/assets/tinymce.js"></script> -
Create a
<textarea>with the initial contentHello, World!for TinyMCE by adding the following lines toapp/views/welcome/index.html.erb:<%= text_area_tag :content, "Hello, World!", :class => "tinymce" %> <%= tinymce %> -
On a command line, from the project’s root directory, start the Ruby on Rails server.
rails server
The page containing the TinyMCE will be accessible at http://localhost:<port>/ (default: http://localhost:3000/).
For information on creating advanced configurations for the third-party TinyMCE Ruby on Rails integration, visit the project on GitHub: Rails Integration for TinyMCE.