<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Rails 6 - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Rails 6 - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 23 Jun 2026 21:16:23 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/rails-6/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ A Quick Look at Action Text for Rails 6.0 ]]>
                </title>
                <description>
                    <![CDATA[ By Arun Mathew Kurian Rails 6.0 is almost here. The stable version will be released on April 30. The Rails 6.0 beta1 was released on January 15. As Rails releases always are, Rails 6.0 is also action-packed. There are two major frameworks newly intro... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/quick-look-at-action-text-in-rails-6-0-12a8f9f7597f/</link>
                <guid isPermaLink="false">66c35d2b56e6b06442afd853</guid>
                
                    <category>
                        <![CDATA[ Rails 6 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Action Text ]]>
                    </category>
                
                    <category>
                        <![CDATA[ rich text editor ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 29 Jan 2019 09:51:36 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*0-LAOoPHs63XCSd3VDJ2Eg.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Arun Mathew Kurian</p>
<p><a target="_blank" href="https://weblog.rubyonrails.org/">Rails 6.0</a> is almost here. The stable version will be released on April 30. The Rails 6.0 beta1 was released on January 15. As Rails releases always are, Rails 6.0 is also action-packed. There are two major frameworks newly introduced, <a target="_blank" href="https://weblog.rubyonrails.org/2018/12/13/introducing-action-mailbox-for-rails-6/">Action Mailbox</a> and <a target="_blank" href="https://weblog.rubyonrails.org/2018/10/3/introducing-action-text-for-rails-6/">Action Text</a>. In this post, let's take a quick look at Action Text by using it in a small app.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*0-LAOoPHs63XCSd3VDJ2Eg.png" alt="Image" width="800" height="301" loading="lazy">
<em>courtesy:wikipedia</em></p>
<h4 id="heading-action-text">Action Text</h4>
<p>Action Text allows us to bring rich text content and editing to Rails. This means we can perform operations like formatting text, embedding images, formatting links, adding lists and other editor-like feature to a text field.</p>
<p>This is done by including the <a target="_blank" href="https://github.com/basecamp/trix">Trix editor</a> into the framework. The RichText content generated by the Trix editor is saved in its own RichText model that’s associated with any existing Active Record model in the application. All embedded images or other attachments are automatically stored using <a target="_blank" href="https://edgeguides.rubyonrails.org/active_storage_overview.html">Active Storage.</a></p>
<p>Let us start building our Rails app which will be a blogger app. The app is created in Rails 6.0, so the ruby version must be &gt;2.5.</p>
<p>In the terminal type</p>
<pre><code>rails <span class="hljs-keyword">new</span> blog --edge
</code></pre><p>The -- edge flag fetches the latest rails version or edge version of the rails.</p>
<p>Action Text expects web packer and ActiveStorage to be installed. The active storage is already present in the Rails app. So we need</p>
<pre><code>gem “image_processing”, “~&gt; <span class="hljs-number">1.2</span>” #uncomment <span class="hljs-keyword">from</span> Gemfilegem ‘webpacker’
</code></pre><p>in the gem file.</p>
<p>Now run</p>
<pre><code>bundle install.
</code></pre><p>Next, we need to create a config/webpacker.yml:</p>
<pre><code>bundle exec rails webpacker:install
</code></pre><p>Now let us start our Rails Server.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*YXa6Y6mfxGa2E2m5hnwuug.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>Great, let’s quickly build our app. The app will have only one model Article.</p>
<p>Let us create a controller for articles:</p>
<pre><code>rails g controller Articles index <span class="hljs-keyword">new</span> create show edit update destroy — no-helper — no-test-frameworks
</code></pre><p>And then configure our routes:</p>
<pre><code>Rails.application.routes.draw <span class="hljs-keyword">do</span> resources :articlesend
</code></pre><p>Next, we need to create our model. Our Articles model will have two fields: they are <strong>title</strong> and <strong>text</strong>. text must be the field that accepts Rich Text Format. So in the migration, we need to add only the title field. The text field will be handled by ActionText.</p>
<p>Let’s generate the model</p>
<pre><code>rails g model Articles title:string — no-test-framework
</code></pre><p>and run the migrations:</p>
<pre><code>rails db:migrate
</code></pre><p>Now let us add ActionText part. For that first run</p>
<pre><code>rails action_text:install
</code></pre><p>This will add all the dependencies required by Action Text. Most notably, this will add a new file <strong>javascript/packs/application.js</strong> and two action-storage migrations.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*1nE9nc8I6E2jC-EnEy394A.png" alt="Image" width="800" height="465" loading="lazy"></p>
<p>Run the migrations again using</p>
<pre><code>rails db:migrate
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/1*AzLR2ezD1weUwRXHKghCTQ.png" alt="Image" width="718" height="208" loading="lazy"></p>
<p>Now we can add the text part of our model. Go to <strong>app/models/article.rb</strong> and add the following line</p>
<p><code>has_rich_text **:text**</code></p>
<p>text is the field name we are providing. It can be anything like body or content etc.</p>
<p>Now our model becomes</p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Article</span> &lt; <span class="hljs-title">ApplicationRecord</span> <span class="hljs-title">has_rich_text</span> :<span class="hljs-title">textend</span></span>
</code></pre><p>Before we build our form, let’s create our controller logic for the creation of articles:</p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ArticlesController</span> &lt; <span class="hljs-title">ApplicationController</span>  <span class="hljs-title">def</span> <span class="hljs-title">create</span>   @<span class="hljs-title">article</span> </span>= Article.new(article_params)   @article.save   redirect_to @article end
</code></pre><pre><code> private def article_params   params.require(:article).permit(:title, :text) end
</code></pre><pre><code>end
</code></pre><p>We can now create the form for the blog. In <strong>app/views/articles/new.rb</strong> add the following form code:</p>
<pre><code>&lt;%= form_with scope: :article, <span class="hljs-attr">url</span>: articles_path, <span class="hljs-attr">local</span>: <span class="hljs-literal">true</span> <span class="hljs-keyword">do</span> |form| %&gt;
</code></pre><pre><code>&lt;p&gt;    &lt;%= form.label :title %&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">%=</span> <span class="hljs-attr">form.text_field</span> <span class="hljs-attr">:title</span> %&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>   <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">%=</span> <span class="hljs-attr">form.label</span> <span class="hljs-attr">:text</span> %&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">%=</span> <span class="hljs-attr">form.rich_text_area</span> <span class="hljs-attr">:text</span> %&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>   <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">%=</span> <span class="hljs-attr">form.submit</span> %&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">%</span> <span class="hljs-attr">end</span> %&gt;</span></span>
</code></pre><p>Notice that for text field we are using <strong>form.rich_text_area</strong> which is provided by Action Text.</p>
<p>Let us render our page:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*zpL22oO9exBtJqvJ75dFPw.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>Awesome!!</p>
<p>We now have an awesome text editor for creating our article.</p>
<p>Before we start playing with the editor, let’s quickly implement the <strong>show</strong> functionality of the blog, so that we can see the articles we have created.</p>
<p>In <strong>app/controllers/articles_controller.rb</strong> add the following function:</p>
<pre><code> def show   @article = Article.find(params[:id]) end
</code></pre><p>Also, we need to create a view for this.</p>
<p>Create the file <strong>app/views/articles/show.html.erb</strong> and add the following code:</p>
<pre><code>&lt;p&gt;Article Title:<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">%=</span> @<span class="hljs-attr">article.title</span> %&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span></span>&lt;<span class="hljs-regexp">/p&gt;&lt;p&gt;Article Text:&lt;strong&gt;&lt;%= @article.text %&gt;&lt;/</span>strong&gt;&lt;/p&gt;
</code></pre><pre><code>&lt;%= link_to ‘Create <span class="hljs-keyword">new</span>’,new_article_path %&gt;
</code></pre><p>That's it. Our app is done. Now let's check the various features available in the text editor provided by ActionText.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*_tH1tezWuI8khKwrieWjZw.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>We can see that ActionText provides almost all the functionalities of a normal rich text-editor like formatting the text as bold, italic, adding strike-throughs, quotes, links, dragging and dropping images, etc.</p>
<p>After saving this, we can see the saved post from the show page.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*QD3WpW9992Wzo9a1yPyHgw.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>Great!</p>
<p>This is a very small example that displays the potential of ActionText. Hope it was helpful. Do give it a try.</p>
<p>A vast majority of web apps deal with rich content in some way. So I believe this new feature of Rails can make the lives of many developers easier.</p>
<p>Kudos to DHH and all the awesome people behind this.</p>
<p><a target="_blank" href="https://github.com/amkurian/Rails-6.0_action_text_demo">https://github.com/amkurian/Rails-6.0_action_text_demo</a></p>
<p>Some Useful Links:</p>
<p><a target="_blank" href="https://edgeguides.rubyonrails.org/action_text_overview.html"><strong>Action Text Overview - Ruby on Rails Guides</strong></a><br><a target="_blank" href="https://edgeguides.rubyonrails.org/action_text_overview.html">_Action Text OverviewThis guide provides you with all you need to get started in handling rich text content.After…_edgeguides.rubyonrails.org</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
