Using TinyMCE from the Tiny Cloud CDN with Ruby on Rails
The Tiny Cloud can be used to integrate TinyMCE into Ruby on Rails projects. This procedure creates a basic Ruby on Rails application containing a TinyMCE editor.
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 index
This creates a controller named
Welcome
with 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 setindex
as the project home page. For example:Rails.application.routes.draw do get 'welcome/index' root 'welcome#index' end
-
-
Add the following lines within the
<head>
element ofapp/views/layouts/application.html.erb
to automatically include TinyMCE on pages using theapplication
layout:<script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/7/tinymce.min.js" referrerpolicy="origin"></script> <script> tinymce.init({ selector: '.tinymce', plugins: 'lists link image table code help wordcount' }); </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" %>
-
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/).