<?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[ Ruby on Rails - 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[ Ruby on Rails - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 09 Jun 2026 04:38:33 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/ruby-on-rails/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ A Brief Introduction to Ruby ]]>
                </title>
                <description>
                    <![CDATA[ Ruby is a programming language designed with developer happiness in mind. Its elegant and intuitive syntax makes coding not only productive but also enjoyable. Ruby stands out with its powerful metaprogramming capabilities, allowing developers to tre... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/a-brief-introduction-to-ruby/</link>
                <guid isPermaLink="false">68a5f79379e37ec1bf4b9b72</guid>
                
                    <category>
                        <![CDATA[ Ruby ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ sinatra ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Mark Mahoney ]]>
                </dc:creator>
                <pubDate>Wed, 20 Aug 2025 16:28:03 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1755707266513/270f71d0-0e56-46f6-bba1-7b369dd97f1d.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Ruby is a programming language designed with developer happiness in mind. Its elegant and intuitive syntax makes coding not only productive but also enjoyable. Ruby stands out with its powerful metaprogramming capabilities, allowing developers to treat code as data and manipulate it at runtime.</p>
<p>While many modern languages offer similar features, Ruby consistently delivers a seamless and joyful experience. Whether you're building a startup MVP, a scalable enterprise application, or a lightweight API, Ruby has you covered with frameworks like <a target="_blank" href="https://rubyonrails.org/">Rails</a> and <a target="_blank" href="https://sinatrarb.com/">Sinatra</a>.</p>
<p>Despite the growing popularity of JavaScript and Python, Ruby remains a valuable language to learn, not just for its utility, but for how it teaches you to write clean, expressive, and maintainable code.</p>
<p>If you've heard of Ruby but never used it, this tutorial is the perfect starting point. Designed to be completed in an afternoon, it offers a glimpse into what makes Ruby so beloved by developers. While it doesn't cover every aspect of the language, Ruby's intuitive nature ensures you'll be well prepared to dive right into frameworks like Sinatra or Rails after completing it.</p>
<h2 id="heading-code-playbacks"><strong>Code Playbacks</strong></h2>
<p>Code playbacks are a unique way to learn about programming. They are guided walkthroughs of code, allowing you to see not just the code itself but also the thought process behind it. This approach helps you understand not only what the code does, but <em>why</em> it was written that way. Here is a short video to show how to move through a code playback:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/uYbHqCNjVDM" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p> </p>
<p>By registering on <a target="_blank" href="https://playbackpress.com/books">Playback Press</a>, you’ll gain access to an AI assistant that can answer your questions about the code. This makes learning even more interactive and personalized. Watch this video to see how to work with it:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/WAPql5KZFR4" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p> </p>
<h2 id="heading-a-brief-introduction-to-ruby"><strong>A Brief Introduction to Ruby</strong></h2>
<p>You can find my entire collection of Ruby code playbacks in my free book, <a target="_blank" href="https://playbackpress.com/books/rubybook/">"A Brief Introduction to Ruby"</a>. Here's a quick look at what you'll learn:</p>
<h3 id="heading-highlights"><strong>Highlights</strong></h3>
<ul>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/1"><strong>1.1 Hello Ruby!!!</strong></a>: Write your first Ruby program and learn how to run it from the terminal.</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/2"><strong>1.2 Variables and Types</strong></a>: Explore Ruby's variables, constants, and string interpolation.</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/3"><strong>1.3 Selection and Looping</strong></a>: Master control flow with if statements, loops, and ranges.</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/4"><strong>1.4 Arrays</strong></a>: Work with arrays, one of Ruby's most versatile data structures.</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/5"><strong>1.5 Hashes</strong></a>: Learn about hashes, Ruby's equivalent of dictionaries or associative arrays.</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/6"><strong>1.6 Methods</strong></a>: Write reusable code with methods, parameters, and return values.</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/7"><strong>1.7 Closures</strong></a>: Discover how to pass code into methods and execute it with <code>yield</code>.</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/8"><strong>1.8 Iterators</strong></a>: Simplify data iteration with Ruby's powerful higher-order methods.</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/9"><strong>1.9 Classes in Ruby</strong></a>: Build objects with classes, instance variables, and inheritance.</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/10"><strong>1.10 Interacting Classes</strong></a>: Create cooperating classes and explore Ruby's "duck typing."</p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/rubybook/chapter/1/11"><strong>1.11 Unit Testing in Ruby</strong></a>: Write tests to ensure your code works as expected.</p>
</li>
</ul>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>Ready to start your Ruby journey? Begin with the first playback and experience how fun and intuitive Ruby can be. Whether you're a complete beginner or an experienced developer, there's something here for everyone!</p>
<p>I’d love to hear your thoughts! Feel free to share your comments, questions, or feedback via email: <a target="_blank" href="https://file+.vscode-resource.vscode-cdn.net/Users/mmahoney/Dropbox/animCPPBook2021/devToBlogPosts/ruby/mark@playbackpress.com">mark@playbackpress.com</a>. Your input helps me improve and create even better content.</p>
<p>If you’ve found this tutorial helpful, consider supporting my work through <a target="_blank" href="https://github.com/sponsors/markm208">GitHub Sponsors</a>. Your contributions help cover hosting costs and keep Playback Press free for everyone. Thank you for helping me continue creating educational resources for the developer community!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Add Categories to a Ruby on Rails Application ]]>
                </title>
                <description>
                    <![CDATA[ By Sampurna Chapagain Creating a category page is essential for most web applications these days. Different kinds of applications like blogs, ecommerce sites, movie streaming platforms, and many others have category features. This article will show h... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-add-categories-to-ruby-on-rails-apps/</link>
                <guid isPermaLink="false">66d460f2868774922c885012</guid>
                
                    <category>
                        <![CDATA[ blog ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 01 Mar 2023 23:31:16 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/02/fcccat.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Sampurna Chapagain</p>
<p>Creating a category page is essential for most web applications these days. Different kinds of applications like blogs, ecommerce sites, movie streaming platforms, and many others have category features.</p>
<p>This article will show how to add categories to Ruby on Rails applications.</p>
<p>This is a beginner-friendly tutorial, so you can follow along even if you have very basic Ruby on Rails knowledge.</p>
<h2 id="heading-how-to-generate-the-blog-scaffold">How to Generate the Blog Scaffold</h2>
<p>Let's first create a new Rails project. Here, we will be using Rails version 6.1.7 and Ruby version 3.0. You can create the new Rails project using the command below:</p>
<pre><code class="lang-ruby">rails new blog_categories
</code></pre>
<p>Now, let's create the new blog scaffold using the following command:</p>
<pre><code class="lang-ruby">rails g scaffold blogs <span class="hljs-symbol">title:</span>string <span class="hljs-symbol">description:</span>text
</code></pre>
<p>This command will create all the necessary files for us to work with the blog's <code>CRUD</code> operations with two database fields <code>title</code> and <code>description</code>. Here, the <code>title</code> is the <code>string</code> field and the <code>description</code> is the <code>text</code> field.</p>
<p>You now need to run the migration with the <code>rails db:migrate</code> command.</p>
<p>Now, head up to your terminal, start the server, and visit the <code>/blogs</code> page. You can see the following result on the browser.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/02/blog.gif" alt="Image" width="600" height="400" loading="lazy">
<em>creating blogs</em></p>
<h2 id="heading-how-to-generate-the-categories-scaffold">How to Generate the Categories Scaffold</h2>
<p>Now, we have come to the main part of the tutorial which is to add categories to our blog articles.</p>
<p>For that, let's create the categories scaffold now with the command below:</p>
<pre><code class="lang-ruby">rails g scaffold categories <span class="hljs-symbol">name:</span>string
</code></pre>
<p>This command will create <code>CRUD</code> for the <code>categories</code>.</p>
<p>Also, you will need to run <code>rails db:migrate</code> to update the schema.</p>
<h3 id="heading-how-to-add-an-association-between-the-blog-and-category-models">How to add an association between the blog and category models</h3>
<p>Next, you need to add an association between the <code>blog</code> and <code>category</code> models.</p>
<p>In <code>Blog.rb</code>:</p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Blog</span> &lt; ApplicationRecord</span>
    belongs_to <span class="hljs-symbol">:category</span>
<span class="hljs-keyword">end</span>

And <span class="hljs-keyword">in</span> <span class="hljs-string">`Category.rb`</span>:

<span class="hljs-string">``</span><span class="hljs-string">`ruby
class Category &lt; ApplicationRecord
    has_many :blogs
end


Now, you need to add the `</span>category_id<span class="hljs-string">` to the `</span>blogs<span class="hljs-string">` table since each blog is associated with a category. You can go to your terminal and add the following migration:

`</span><span class="hljs-string">``</span>ruby
rails g migration add_category_id_to_blogs
</code></pre>
<p>This will create a new migration. You need to add the following code in this migration file:</p>
<pre><code class="lang-ruby">add_column <span class="hljs-symbol">:blogs</span>, <span class="hljs-symbol">:category_id</span>, <span class="hljs-symbol">:integer</span>
</code></pre>
<p>Rails has its own set of conventions and rules. And it's smart enough to recognize that this migration is to add a new database column named <code>category_id</code> to the <code>blogs</code> table.</p>
<p>You now need to pass <code>category_id</code> as a strong parameter in the <code>blogs</code> controller.</p>
<pre><code class="lang-ruby"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">blog_params</span></span>
    params.<span class="hljs-keyword">require</span>(<span class="hljs-symbol">:blog</span>).permit(<span class="hljs-symbol">:title</span>, <span class="hljs-symbol">:content</span>, <span class="hljs-symbol">:category_id</span>)
<span class="hljs-keyword">end</span>
</code></pre>
<p>Now, let's create a few categories from the browser.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/categories.gif" alt="Image" width="600" height="400" loading="lazy">
<em>creating categories from the browser</em></p>
<p>You could also add some validation while creating category. For that, you can update the <code>category.rb</code> file with the following code:</p>
<p>```ruby
class Category &lt; ApplicationRecord
    validates :name, presence: true, uniqueness: true
    has_many :blogs
end</p>
<p>This will add few validations as shown in the GIF below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/validations.gif" alt="Image" width="600" height="400" loading="lazy">
<em>adding validations while creating categories</em></p>
<h3 id="heading-how-to-display-categories-as-a-dropdown-in-the-new-blogs-page">How to display categories as a dropdown in the new blogs page</h3>
<p>Now that you can create both blogs and categories, you'll need to display all categories as a dropdown when someone visits the new blog page.</p>
<p>The code for that is shown below:</p>
<p>```ruby</p>
<div>
    &lt;%= form.label :category %&gt;
    &lt;%= form.select :category_id, options_for_select(Category.all.map { |category| [category.name, category.id]})%&gt;
</div>

<p>The <code>select</code> tag creates the dropdown selection box. The <code>options_for_select</code> takes a few arguments. </p>
<p>First, it maps through all categories and returns an array of <code>[c.category, c.id]</code>. The category <code>name</code> gets displayed as a dropdown and the category <code>id</code> of any category the user selects gets passed to the controller. The controller then performs the database insertion for blogs. </p>
<p>You can go to the new blogs URL and create blogs with categories.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/blog1-1.gif" alt="Image" width="600" height="400" loading="lazy">
<em>creating blogs with categories</em></p>
<h3 id="heading-listing-each-categorys-blogs">Listing each category's blogs</h3>
<p>The next part of this tutorial will show you how to list all categories and all blogs associated with each category. We will be displaying this on the categories index page.</p>
<p>For that, you need to add some code in the categories index view.</p>
<p>```ruby</p>
<p id="notice">&lt;%= notice %&gt;</p>

<h1 id="heading-categories">Categories</h1>


    &lt;% @categories.each do |category| %&gt;
      
        &lt;% category.blogs.each do |blog| %&gt;
          
        &lt;% end %&gt;
      
    &lt;% end %&gt;
  <table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Blogs</th>
      <th></th>
    </tr>
  </thead>

  <tbody><tr>
        <td>&lt;%= category.name %&gt;</td><td>&lt;%= blog.title %&gt;</td></tr></tbody>
</table>

<p><br></p>
<p>&lt;%= link_to 'New Category', new_category_path %&gt;</p>
<p>Here, it's iterating through all categories in order to display each category's name. After we are done with displaying the category name, the next part is to display all blogs associated with each category. So, you can iterate through <code>category.blogs</code> from which you can get the blog records. </p>
<p>If you visit the <code>/category</code> route, you can see all categories with their blogs as displayed in the GIF below.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/cat_blogs.gif" alt="Image" width="600" height="400" loading="lazy">
<em>listing each category with blogs</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this tutorial, you learned how you can add categories in your Ruby on Rails applications using one-to-many associations.</p>
<p>If you liked this article, please consider <a target="_blank" href="https://www.buymeacoffee.com/SamChapagain">buying me a coffee</a> ☕.</p>
<p>You can find me on <a target="_blank" href="https://twitter.com/saam_codes">Twitter</a> for various content related to Web Development.</p>
<p>Thanks for reading.</p>
<p>Happy Coding.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Polymorphic Associations in Ruby on Rails ]]>
                </title>
                <description>
                    <![CDATA[ By Sampurna Chapagain Polymorphic association in Ruby on Rails refers to the type of active record association. From the Rails Guide, it allows a single model to belong to more than one other model on a single association. This tutorial assumes that ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/polymorphic-association-ruby-on-rails/</link>
                <guid isPermaLink="false">66d460f951f567b42d9f84b5</guid>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 26 Jan 2023 18:40:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/Add-a-subheading--2-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Sampurna Chapagain</p>
<p>Polymorphic association in Ruby on Rails refers to the type of active record association. From the <a target="_blank" href="https://guides.rubyonrails.org/association_basics.html#polymorphic-associations">Rails Guide</a>, it allows a single model to belong to more than one other model on a single association.</p>
<p>This tutorial assumes that you have some knowledge of a few associations in Rails like the <code>belongs_to</code>, <code>has_one</code>, and <code>has_many</code> associations. </p>
<p>It is a slightly more advanced type of association but it's perfect when you want to connect a model to multiple other models.</p>
<h2 id="heading-the-problem-with-not-using-polymorphic-associations">The Problem with Not Using Polymorphic Associations</h2>
<p>Suppose you want to create an app with features like posts, a forum, and event functionality. </p>
<p>In the initial stage of your app, you might plan to add a comment feature to just the posts model. But as your app grows, you might want to add a similar comment feature to the forum and event models as well (maybe for other models, too, along the line). </p>
<p>Let's see how this would look in the picture below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Comment--1-.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Passing comments to posts, event, and forum models</em></p>
<p>Every time you want to add something that has comments in the app, you have to add a foreign key to the comments table. You would end up writing lots of repetitive code in this process. </p>
<p>This might not be a problem for small applications, but as your app grows this can be a huge issue. And this is where polymorphic associations come in super handy.</p>
<h2 id="heading-how-polymorphic-associations-helps-solve-this-problem">How Polymorphic Associations Helps Solve This Problem</h2>
<p>The solution to the above problem is to use polymorphic associations in Rails. This lets you define a single model which can belong to other different models without having to write repeated code.</p>
<p>Considering the above example, you do not have to add the foreign key to the comments table every time you have to add comments to other models.</p>
<p>With polymorphic associations, you can add just two columns in the comments table, which is very straightforward. Let's see how it works in the next section of this article. </p>
<h2 id="heading-how-to-implement-polymorphic-associations">How to Implement Polymorphic Associations</h2>
<p>To create the new <code>PolyComment</code> model, we will be using the following command:</p>
<p><code>rails g model PolyComment content:text commentable:references{polymorphic}</code></p>
<p>Let's check the <code>PolyComment</code> model now:</p>
<p>``` ruby
class PolyComment &lt; ApplicationRecord
  belongs_to :commentable, polymorphic: true
end</p>
<p>The migration file will look like this:</p>
<p>```ruby
class CreatePolyComments &lt; ActiveRecord::Migration[6.1]
  def change
    create_table :poly_comments do |t|
      t.text :content
      t.references :commentable, polymorphic: true, null: false</p>
<p>      t.timestamps
    end
  end
end</p>
<p>Now, let's run the migration using the <code>rails db:migrate</code> command to update the <code>schema</code> which will have two additional interesting columns.</p>
<p>```ruby
create_table "poly_comments", force: :cascade do |t|
    t.text "content"
    t.string "commentable_type", null: false
    t.integer "commentable_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["commentable_type", "commentable_id"], name: "index_poly_comments_on_commentable"
  end</p>
<p>The columns <code>commentable_type</code> and <code>commentable_id</code> help setup the polymorphic associations.</p>
<p><code>commentable_type</code> stores the name of models like <code>Event</code>, <code>Post</code>, or <code>Forum</code> in this case. And <code>commentable_id</code> stores the <code>id</code> that corresponds to that model.</p>
<p>Now, let's generate the three models with the following commands:</p>
<p><code>rails g model Post title</code></p>
<p><code>rails g model Event title</code></p>
<p><code>rails g model Forum title</code></p>
<p>Now, we need to add <code>has_many</code> relationships in these three models:</p>
<p>Post.rb
```ruby
class Post &lt; ApplicationRecord
    has_many :poly_comments, as: :commentable
end</p>
<p>Event.rb
```ruby
class Event &lt; ApplicationRecord
    has_many :poly_comments, as: :commentable
end</p>
<p>Forum.rb
```ruby
class Forum &lt; ApplicationRecord
    has_many :poly_comments, as: :commentable
end</p>
<p> You can add comments to as many models as you want based on the above logic.</p>
<h3 id="heading-how-to-test-it-in-the-console">How to test it in the console</h3>
<p>Now, let's play around with the console to test the results:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screenshot-from-2023-01-23-20-08-00.png" alt="Image" width="600" height="400" loading="lazy">
<em>Creating new post</em></p>
<p>Here, we have created a new Post.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screenshot-from-2023-01-23-20-08-25-3.png" alt="Image" width="600" height="400" loading="lazy">
<em>Adding Comment to Post</em></p>
<p> Here, you can see that the value of <code>commentable_type</code> is <code>Post</code> (in the form of a string) since it is associated with the <code>Post</code> model. Also, the value of <code>commentable_id</code> is <code>1</code> since it matches the <code>id</code> of the respective object. </p>
<p>This is how you can add comments for any models you want.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Polymorphic associations make your code DRY (Don't repeat yourself) and bug-free. If you want to connect a model with multiple other models then the polymorphic associations will be a great choice. Using this approach, you do not have to define a separate association for each model.</p>
<p>If you liked this article, please consider <a target="_blank" href="https://www.buymeacoffee.com/SamChapagain">buying me a coffee</a> ☕.</p>
<p>You can find me on <a target="_blank" href="https://twitter.com/saam_codes">Twitter</a> for various content related to Web Development.</p>
<p>Happy Coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Add Search Functionality to a Ruby on Rails Application ]]>
                </title>
                <description>
                    <![CDATA[ By Sampurna Chapagain Nowadays, most web applications have a search feature. Users can use the search feature in order to navigate websites more easily. Implementing a search feature in Ruby on Rails is very easy. By using only a few lines of code yo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-add-search-to-ruby-on-rails-app/</link>
                <guid isPermaLink="false">66d460f3c7632f8bfbf1e4b5</guid>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ search ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 13 Jan 2023 18:22:33 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/markus-winkler-afW1hht0NSs-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Sampurna Chapagain</p>
<p>Nowadays, most web applications have a search feature. Users can use the search feature in order to navigate websites more easily.</p>
<p>Implementing a search feature in Ruby on Rails is very easy. By using only a few lines of code you can set it up.</p>
<p>This tutorial assumes that you have basic knowledge of Ruby on Rails. If you need an introduction to the framework, <a target="_blank" href="https://www.freecodecamp.org/news/learn-ruby-on-rails-video-course/">check out this course</a>.</p>
<h3 id="heading-what-will-we-be-creating">What Will We Be Creating</h3>
<p>By the end of this article, we'll have a web app with a search feature that looks like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/searchresults.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Demo of the app</em></p>
<h2 id="heading-how-to-generate-the-post-scaffold">How to Generate the Post Scaffold</h2>
<p>Here we're using Ruby version 3.0 and Rails version 6.1.7.</p>
<p>Rails scaffold refers to the automatic generation of files that forms the basic structure of the rails project. These files include controllers, views, models, routes, and migration.</p>
<p>Now, let's scaffold the post using the following command:</p>
<p><code>rails g scaffold post title description:text</code></p>
<p>Now, you need to run the migration in order to update the schema using the <code>rails db:migrate</code> command. </p>
<p>If you run the server now, you can perform all the CRUD operations in the project.</p>
<h2 id="heading-how-to-add-haml-to-the-project">How to Add Haml to the Project</h2>
<p>You will be using haml in views instead of erb. You can do this by simply adding <code>gem 'haml', '~&gt; 6.1', '&gt;= 6.1.1'</code> in the gemfile. You can get all gems from the <a target="_blank" href="https://rubygems.org/">https://rubygems.org/</a> website. </p>
<p>Haml uses indentation and its main purpose is to make the markup look beautiful.</p>
<p>Now, you can use the haml extension in views instead of erb. So, you can rename application.html.erb to application.html.haml. You can also use <a target="_blank" href="https://awsm-tools.com/html-to-haml">html to haml tools</a> for converting erb to haml files. </p>
<h2 id="heading-how-to-build-the-search-form">How to Build the Search Form</h2>
<p>Once that's done, you're at the main part of the tutorial. So, let's add the form in the application.html.haml file. </p>
<p>```ruby
%body
    %form{action: "/search"}
      %input{placeholder: "Search",name: "key",type: "text"}
      %button{type: "submit"} Search
    = yield</p>
<p>This code will generate a form in the whole application.</p>
<p>Here, you are passing the action attribute which will redirect to the search page when the form is submitted. Also, you are passing the key as the name attribute for the input element.</p>
<p>If you submit the form now you will get the following routing error:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/searcherror.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Screen recording showing the routing error.</em></p>
<h3 id="heading-how-to-add-root-and-search-routes">How to Add Root and Search Routes</h3>
<p>Let's add a few routes in the routes.rb file.</p>
<p>```ruby
root "posts#index"</p>
<p>get '/search', to: "posts#search"</p>
<p>The first route makes the index view the root page.</p>
<p>The second route adds the search route as a get method. So, you need to create a search action with some SQL queries in the posts controller.</p>
<h3 id="heading-how-to-add-the-search-action-in-the-controller">How to Add the Search Action in the Controller</h3>
<p>In the above route, the search route is looking for search actions in the posts controller. So, let's create it.</p>
<p>```ruby
def search
    key = "%#{params[:key]}%"
    @posts = Post.where("name LIKE ?", key)
end</p>
<p>Here, in the search action, the <code>key</code> variable holds the value of <code>params[:key]</code>. You get the value of <code>params[:key]</code> after the form submission. </p>
<p>The <code>%</code> symbol matches zero, one, or multiple characters. The above code uses two <code>%</code> symbols before and after <code>params[:key]</code> to match the value of <code>params[:key]</code> present in any position with the <code>name</code> column records in the database.</p>
<p>It is using the <code>LIKE</code> operator with a <code>where</code> clause in order to perform a search. <code>?</code> is a placeholder value in queries and gets replaced with whatever arguments get passed – for example, <code>key</code> in this case. </p>
<p>Additionally, you can also use the <code>or</code> operator for searching multiple columns in the database.</p>
<p><code>@posts = Post.where("name LIKE ? or description LIKE ?", key, key)</code></p>
<p>You can search for both the <code>name</code> and <code>description</code> records using the above code. </p>
<h3 id="heading-how-to-add-the-necessary-views">How to Add the Necessary Views</h3>
<p>Next, you need to add a search.html.haml file. But before that, let's create a new partial called _post.html.haml file in order to reuse the code. The post partial will look like this:</p>
<p>```ruby</p>
<p>%tbody
  -@posts.each do |post|
    %tr
      %td= post.name
      %td= post.description
      %td= link_to 'Show', post
      %td= link_to 'Edit', edit_post_path(post)
      %td= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' }
%br/
= link_to 'New Post', new_post_path</p>
<p>This is how the search.html.haml file will look:</p>
<p>```ruby</p>
<p>%h1 Search Results
%p#notice= notice
%h1 Posts
%table
    %thead
        %tr
            %th Name
            %th Description
            %th{colspan: "3"}
    =render "post"</p>
<p>And, you need to update the index.html.haml file as well.</p>
<p>```ruby</p>
<p>%p#notice= notice
%h1 Posts
%table
    %thead
        %tr
            %th Name
            %th Description
            %th{colspan: "3"}
    = render "post"</p>
<p>By doing this, you are using the post partial in both index and search view. </p>
<p>Finally, the search feature works as expected.</p>
<p>You can find the full source code of this project in this <a target="_blank" href="https://github.com/SampurnaC/search_demo_app_fcc">GitHub repository</a>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>This is how you can create a search feature in a Rails application. </p>
<p>If you liked this article, please consider <a target="_blank" href="https://www.buymeacoffee.com/SamChapagain">buying me a coffee</a> ☕. </p>
<p>You can find me on <a target="_blank" href="https://twitter.com/saam_codes">Twitter</a> for various content related to Web Development. </p>
<p>Thanks for reading. </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn Ruby on Rails by Creating a Friends List App ]]>
                </title>
                <description>
                    <![CDATA[ Ruby on Rails is a web development framework that makes developing full stack web apps simpler and quicker compared to many other frameworks. Ruby on Rails provides the basic structure needed to create web pages, web services, and databases. We've re... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-ruby-on-rails-video-course/</link>
                <guid isPermaLink="false">66b2050408bc664c3c097edd</guid>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Tue, 10 Nov 2020 16:55:36 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/11/rails.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Ruby on Rails is a web development framework that makes developing full stack web apps simpler and quicker compared to many other frameworks. Ruby on Rails provides the basic structure needed to create web pages, web services, and databases.</p>
<p>We've released a full course on the freeCodeCamp.org YouTube channel that will help you learn Ruby on Rails by building a friends list app.</p>
<p>The course was created by John Elder from Codemy.com. John has written two best-selling Ruby on Rails books and has created many video courses.</p>
<p>In this course you will build an app that keeps track of your friends' contact information. You will learn how to implement CRUD functionality. CRUD stands for Create, Read, Update, and Destroy and is used in almost all web apps.</p>
<p>Here are the topics covered in this course:</p>
<ul>
<li>Introduction and Installation</li>
<li>First Webpage and MVC Overview</li>
<li>Application Partial Links and New Pages</li>
<li>CRUD Scaffold</li>
<li>Style App with Bootstrap</li>
<li>Style Devise Views</li>
<li>Associations</li>
<li>Style Modifications</li>
<li>Fun With the Controller</li>
<li>Git, GitHub, and Heroku</li>
</ul>
<p>Watch the full course on <a target="_blank" href="https://www.youtube.com/watch?v=fmyvWz5TUWg">the freeCodeCamp.org YouTube channel</a> (4-hour watch).</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ 5 Helpful Visual Studio Plugins for Ruby on Rails Developers ]]>
                </title>
                <description>
                    <![CDATA[ By Vishnu Chilamakuru In this article, I'll share some of the plugins that I use to make development with Ruby on Rails easier and more fun. Why use these tools? Development tools play a significant role in a developer's life. If you are a junior dev... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/visual-studio-plugins-for-ruby-on-rails-developers/</link>
                <guid isPermaLink="false">66d46171d1ffc3d3eb89de78</guid>
                
                    <category>
                        <![CDATA[ plugins ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 03 Sep 2020 06:16:55 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/08/visual_studio_ruby_on_rails-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Vishnu Chilamakuru</p>
<p>In this article, I'll share some of the plugins that I use to make development with Ruby on Rails easier and more fun.</p>
<h2 id="heading-why-use-these-tools">Why use these tools?</h2>
<p>Development tools play a significant role in a developer's life. If you are a junior developer and are just getting started working on projects, then knowing about the appropriate tools is a must. </p>
<p>These tools can save you a lot of time and they allow you to code more efficiently and thus increase your productivity.</p>
<p>If you are Ruby on Rails developer who's looking for free development tools, I would recommend Visual Studio. It has a ton of plugins, like the ones mentioned below, and they have helped me increase my productivity a lot.</p>
<p><em>Note: All visual studio plugins are available on the</em> <a target="_blank" href="https://marketplace.visualstudio.com/"><em>Visual Studio Marketplace</em></a> <em>for free.</em></p>
<p>So let's dive in.</p>
<h2 id="heading-rubyhttpsmarketplacevisualstudiocomitemsitemnamerebornixruby"><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby">Ruby</a></h2>
<p>With ~1.3M downloads, this is one of the most popular plugins for Ruby. It provides enhanced Ruby language and debugging support. </p>
<p>With enhanced debugging support, developers can set breakpoints and inspect the local and global variables in debug mode. This helps to debug any issues easily and in quick time. </p>
<p>This plugin also supports code formatting via <strong><em>rubocop</em></strong> which is very much needed when you are working with team of developers to maintain consistent code format.</p>
<p>Ruby plugin has the following features:</p>
<blockquote>
<ul>
<li><p>Automatic Ruby environment detection with support for rvm, rbenv, chruby, and asdf  </p>
</li>
<li><p>Lint support via RuboCop, Standard, and Reek  </p>
</li>
<li><p>Format support via RuboCop, Standard, Rufo, and RubyFMT  </p>
</li>
<li><p>Basic Intellisense support  </p>
</li>
<li><p>Ruby debugging support  </p>
</li>
</ul>
<p>Source: <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby">Ruby</a></p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/Screenshot-2020-08-30-at-3.13.49-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-railshttpsmarketplacevisualstudiocomitemsitemnamebung87rails"><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=bung87.rails">Rails</a></h2>
<p>This is another popular plugin for Rails which provides enhanced Rails support. </p>
<p>ERB HTML templating is widely used in Rails ecosystem as views to render HTML pages for websites. The Rails plugin has support for the <code>.erb</code> syntax and also provides auto-completion for popular HTML tags like stylesheet, meta tags, asset tags, and so on. </p>
<p>This plugin also helps to switch between Rails views (<code>*.erb</code> files) easily. It also helps you see online documentation of any methods or commands easily side by side.</p>
<p>Here are some of the features this plugin supports:</p>
<blockquote>
<ul>
<li><p>Ruby on Rails “Asset Helpers” and “Tag Helpers” snippets.  </p>
</li>
<li><p>.erb syntax highlights.  </p>
</li>
<li><p>Navigation between related files through command.  </p>
</li>
<li><p>Go to Definition.  </p>
</li>
<li><p>View path suggestion, Model’s static method suggestion, and Model’s field suggestion.  </p>
</li>
<li><p>Open the online document to the side through command.  </p>
</li>
</ul>
<p>Source: <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=bung87.rails">Rails</a></p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/vscode-rails.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=bung87.rails">VSCode Rails</a></em></p>
<h2 id="heading-ruby-solargraphhttpsmarketplacevisualstudiocomitemsitemnamecastwidesolargraph"><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=castwide.solargraph">Ruby Solargraph</a></h2>
<p>Ruby Solargraph is one of the most helpful plugins on this list, and provides IntelliSense, code completion, and inline documentation for Ruby. </p>
<p>Inline documentation helps you view all the allowed methods of the class/object, and also helps you easily understand the definition of each method and its arguments.</p>
<p>This is one of the plugins I have personally used many times to refer to a Ruby method's documentation, arguments for a method, and so on.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/vscode-solargraph-0.34.1.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=castwide.solargraph">VSCode Solargraph</a></em></p>
<h2 id="heading-vscode-endwisehttpsgithubcomkaiwoodvscode-endwise"><a target="_blank" href="https://github.com/kaiwood/vscode-endwise">Vscode Endwise</a></h2>
<p>This is my favorite extension that can save you a lot of time and headaches. This extension automatically adds  <code>end</code> to all your Ruby code blocks.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/endwise.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://github.com/kaiwood/vscode-endwise">VSCode Endwise</a></em></p>
<h2 id="heading-rails-db-schemahttpsmarketplacevisualstudiocomitemsitemnameaki77rails-db-schema"><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=aki77.rails-db-schema">Rails Db Schema</a></h2>
<p>This plugin helps you define a DB schema and also enables auto-completion for Rails DB schemas. </p>
<p>While defining schemas or creating tables for any Entity, this plugin enables and autocompletes syntax for all your DDLs (Database definition language) like <code>create_table</code>, <code>create_index</code>, <code>delete_table</code>, <code>update_table</code>, and so on. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/definition.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=aki77.rails-db-schema">VSCode DB Schema</a></em></p>
<p>It helps in autocomplete of all attributes of any database entity. For example, if <code>User</code> has <code>email</code>, <code>name</code>, and <code>date_of_birth</code> attributes, this plugin will automatically detect the definition of entity and autocompletes its attributes when you type <code>User</code>. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/autocompletion.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=aki77.rails-db-schema">VSCode DB Schema</a></em></p>
<h2 id="heading-why-use-visual-studio">Why use Visual Studio?</h2>
<p>There are many other IDE options for Ruby on Rails developers like RubyMine (the enterprise version), Sublime, Vim, and so on. </p>
<p>But my personal favorite is Visual Studio as it has extensive plugin support for multiple languages like Golang, PHP, Node.js, and more. So it's the default IDE, especially for polyglot developers.</p>
<p>Even though visual studio lacks few features compared to RubyMine like getting support for the latest Rails version updates, it covers the majority of the features required for development via community plugins.</p>
<p>If this article was useful, please share it with your network. Also, follow me on <a target="_blank" href="https://twitter.com/vishnuchi">Twitter</a> to know when I publish my next article.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Ruby on Rails Explained ]]>
                </title>
                <description>
                    <![CDATA[ Ruby on Rails is a server-side framework (gem) built on the Ruby language to make websites. It includes everything you need to build web applications and has a big community. Ruby on Rails is an opinionated framework, and emphasizes the use of conven... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/ruby-on-rails-explained/</link>
                <guid isPermaLink="false">66c35e1c39357f944697661f</guid>
                
                    <category>
                        <![CDATA[ Ruby ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ toothbrush ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 01 Feb 2020 00:00:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9cff740569d1a4ca3552.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><a target="_blank" href="http://rubyonrails.org/">Ruby on Rails</a> is a server-side framework (gem) built on the Ruby language to make websites. It includes everything you need to build web applications and has a big community.</p>
<p>Ruby on Rails is an opinionated framework, and emphasizes the use of convention over configuration (CoC), and don't repeat yourself (DRY) practices. Rails can best be described as a model-view-controller (MVC) framework, and provides sensible defaults and structures for rapid application development. Lately, Rails has integrated an API module to make the creation of web-services faster and easier.</p>
<p>Ruby on Rails was created by David Heinemeir Hansson and is currently on it’s 6th version.</p>
<h2 id="heading-how-to-install-rails"><strong>How to install Rails</strong></h2>
<p>Rails is downloaded in the same way as any other Ruby gem: with the <code>gem install</code> command. Before we download it, we’ll need to <a target="_blank" href="https://www.ruby-lang.org/">download Ruby</a>. Afterwards we’re only 3 words away from starting with Ruby on Rails:</p>
<pre><code class="lang-shell">$ gem install rails
</code></pre>
<p>Rails ships with sqlite3 as the default database, which is a simple file on disk. You need to install MySQL or PostgreSQL if you want to use something more robust.</p>
<h2 id="heading-how-to-create-a-rails-application"><strong>How to create a Rails application</strong></h2>
<ol>
<li>After you install Ruby on Rails, it’s very simple to create a brand new application, we’ll just need 3 more words:</li>
</ol>
<pre><code class="lang-shell">$ rails new your_application_name
</code></pre>
<ol start="2">
<li>If you want to use MySQL:</li>
</ol>
<pre><code class="lang-shell">$ rails new &lt;application_name&gt; -d mysql
</code></pre>
<ol start="3">
<li>If you want to use Postgres:</li>
</ol>
<pre><code class="lang-shell">$ rails new &lt;application_name&gt; -d postgresql
</code></pre>
<ol start="4">
<li>This command will create a folder with the _your_application<em>name</em> you informed in the last command. Next step is to go to the new directory you’ve just created:</li>
</ol>
<pre><code class="lang-shell">$ cd your_application_name
</code></pre>
<ol start="5">
<li>Get the necessary gems and software packages before running your application:</li>
</ol>
<pre><code class="lang-shell">$ bundle install
</code></pre>
<ol start="6">
<li>To run the rails server and see if everything went accordingly is also fast:</li>
</ol>
<pre><code class="lang-shell">$ rails server
</code></pre>
<p>It couldn’t be anymore simple! Well, this isn’t actually 100% true, we could make it even smaller by reducing the <code>rails server</code> command to:</p>
<pre><code class="lang-shell">$ rails s
</code></pre>
<ol start="7">
<li>Now with your preferred browser, go to <code>http://localhost:3000</code> and you’ll see: “Yay! You’re on Rails!”</li>
</ol>
<h3 id="heading-alternative-method-for-creating-a-rails-application"><strong>Alternative method for creating a Rails application</strong></h3>
<ol>
<li>Create a new directory:</li>
</ol>
<pre><code class="lang-shell">$ mkdir &lt;application_name&gt;
</code></pre>
<ol start="2">
<li>Go into the new directory:</li>
</ol>
<pre><code class="lang-shell">$ cd &lt;application_name&gt;
</code></pre>
<ol start="3">
<li>Create the Rails application using the Unix dot notation. This results in assigning the name of the directory to the new application:</li>
</ol>
<pre><code class="lang-shell">$ rails new .
</code></pre>
<ol start="4">
<li>Start exploring the framework of the application you just created. To see a useful table of the folder structure, check out <a target="_blank" href="https://guides.rubyonrails.org/getting_started.html">Getting Started with Rails</a>.</li>
</ol>
<h2 id="heading-convention-over-configuration"><strong>Convention over Configuration</strong></h2>
<p><em>Convention over Configuration</em> means a developer only needs to specify unconventional aspects of the application. For example, if there is a class <code>Sale</code> in the model, the corresponding table in the database is called <code>sales</code> by default. It is only if one deviates from this convention, such as calling the table “products sold”, that the developer needs to write code regarding these names. Generally, Ruby on Rails conventions lead to less code and less repetition.</p>
<h2 id="heading-what-is-mvc"><strong>What is MVC?</strong></h2>
<p>Model (Active record) contains the business logic and interacts with the database. Views (Action views) all of the HTML files and structure. Controller (Action controller) interacts with the views and model to direct the actions of the application.</p>
<h2 id="heading-dry-dont-repeat-yourself"><strong>DRY - Don’t Repeat Yourself</strong></h2>
<p><em>Don’t repeat yourself</em> means that information is located in a single, unambiguous place. For example, using the ActiveRecord module of Rails, the developer does not need to specify database column names in class definitions. Instead, Ruby on Rails can retrieve this information from the database based on the class name.</p>
<h2 id="heading-ruby-on-rails-is-open-source"><strong>Ruby on Rails is open source</strong></h2>
<p>Not only is it free to use, you can also help make it better. More than 4,500 people have already contributed code to <a target="_blank" href="https://github.com/rails/rails">Rails</a>. It’s easier than you think to become one of them.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to painlessly set up your Ruby on Rails dev environment with Docker ]]>
                </title>
                <description>
                    <![CDATA[ By Jonathan Cunanan You've likely heard about Docker terms like containers, images, services, volumes, network, Dockerfile, docker-compose file, right? Or you've watched some videos about what it is, but you're not sure how can it apply to your daily... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/painless-rails-development-environment-setup-with-docker/</link>
                <guid isPermaLink="false">66d45f6536c45a88f96b7ce5</guid>
                
                    <category>
                        <![CDATA[ beginners guide ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Devops ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Docker ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 15 Aug 2019 21:17:03 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/08/image-136-2.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Jonathan Cunanan</p>
<p>You've likely heard about Docker terms like containers, images, services, volumes, network, Dockerfile, docker-compose file, right? Or you've watched some videos about what it is, but you're not sure how can it apply to your daily life as a developer? </p>
<p>That's what I first thought after watching videos about Docker. Not only can Docker run web-apps, servers, and databases, but it can also be a local development environment! I wrote this article not only so you can learn how to do it, but also for me, so I won't forget it. Let's get started!</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-why-docker">Why Docker?</a></li>
<li><a class="post-section-overview" href="#heading-installing-docker-and-including-ignorefiles">Installing docker and Ignorefiles</a></li>
<li><a class="post-section-overview" href="#heading-dockerfile-and-docker-compose-file">Dockerfile and Docker-Compose</a></li>
<li><a class="post-section-overview" href="#heading-building-and-running-the-container">Building and Running the Container</a></li>
<li><a class="post-section-overview" href="#heading-test-run-a-rails-app">Making new rails app and starting the server</a></li>
<li><a class="post-section-overview" href="#heading-cleaning-up">Cleaning up</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion and repo</a></li>
</ul>
<h2 id="heading-why-docker">Why Docker?</h2>
<p>Why use docker? Why not just install it on your local machine, and install Ruby Version Manager (rvm) or Ruby Environment (rbenv)? </p>
<p>Setting up Ruby On Rails with with these tools is great. It took me over 3 hours of installing, troubleshooting, and searching the documentation to get it working. But recently, I got my mac reformatted. But I didn't list or take note of the websites I've visited to make it work on my machine. I forgot how to install it again and it's a pain to repeat the steps. </p>
<p>This is where Docker shines. Install docker, load your dockerfiles, run a few commands in your terminal, you're already setup! And also, what if you want to uninstall all that you did? It's hard to track what steps to undo. With Docker, it's just a few commands to cleanup.</p>
<p>When I was watching an <a target="_blank" href="https://www.pluralsight.com/courses/docker-web-development">online tutorial about docker</a>, Dan Wahlin, the teacher, said that one of the benefits of docker is to accelerate developer on-boarding. Dan said in his tutorial: </p>
<blockquote>
<p> <em>"Docker can help there because we can make one or more images that can then be converted into running containers, and those containers can run on our different developer, and even designer machines."</em></p>
</blockquote>
<p>Let's say you have a team of developers, designers, and testers, and have an app with a back-end server, database server, and caching server. You have 12 clean slate machines, with a combination of linux and mac computers. Do you really want to go install, troubleshoot, and follow varying installation instructions that depend on the machine? Then make the pieces work, one-by-one on every machine, without the assurance of they won't encounter any varying errors along the way? </p>
<p>This is why I took time to study Docker. With a few commands and a few lines of a configuration file, you're already setup. In the next section, we'll get our hands dirty with docker setup.</p>
<h2 id="heading-installing-docker-and-including-ignorefiles">Installing Docker and including Ignorefiles</h2>
<h3 id="heading-1-install-docker">1. Install Docker</h3>
<p>I'm not gonna talk much about installing docker, there are many videos out there. But usually, it's just download and open the installer, register an account on dockerhub, and you're good to go. Check out <a target="_blank" href="https://docs.docker.com/install/">Docker installation docs</a>.</p>
<h3 id="heading-2-make-a-dockerignore-file">2. Make a <code>.dockerignore</code> file</h3>
<p>What is a dockerignore file? Dockerignore file just tells Docker which files to ignore in it's container. An example is when you have a minified assets, js, css files, that gets changed from time to time whenever you change the original code. This also applies to gitignore files. Usually, the list of recommended files to ignore are usually found in the internet. You can <a target="_blank" href="https://gist.github.com/neckhair/ace5d1679dd896b71403fda4bc217b9e">copy this gist</a> on your own <code>.dockerignore</code> .</p>
<p>And if you use git, put <a target="_blank" href="https://www.gitignore.io/api/node,ruby,rails,linux,macos">this snippet of code</a> in your <code>.gitignore</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-140.png" alt="Image" width="600" height="400" loading="lazy">
<em>The look of your project folder will look similar to this.</em></p>
<p>The ignorefiles are a little bit lenghty that's why I just put links.</p>
<h2 id="heading-dockerfile-and-docker-compose-file">Dockerfile and docker-compose file</h2>
<p>This is where most of the operation happens. Think of these two files as set of instructions Docker follows on how to setup your virtual container. Dockerfile and docker-compose file works hand in hand. You can have multiple Dockerfiles for different services, and one docker-compose file to tie them up together.</p>
<h3 id="heading-3-make-a-file-named-dockerfile">3. Make a file named <code>Dockerfile</code></h3>
<p>A Dockerfile is a file with set of rules you'll set that docker will follow. There are pre-built set of rules found <a target="_blank" href="https://hub.docker.com/">on Docker hub</a>. An example is pre-built installation instructions for MySQL, or PHP, or Node.js. After making your <code>Dockerfile</code>, put this code on your Dockerfile. And I'll go through a brief explanation on what does these lines do.</p>
<pre><code class="lang-dockerfile"><span class="hljs-keyword">FROM</span> ruby

<span class="hljs-keyword">WORKDIR</span><span class="bash"> /home/app</span>

<span class="hljs-keyword">ENV</span> PORT <span class="hljs-number">3000</span>

<span class="hljs-keyword">EXPOSE</span> $PORT

<span class="hljs-keyword">RUN</span><span class="bash"> gem install rails bundler</span>
<span class="hljs-keyword">RUN</span><span class="bash"> gem install rails</span>
<span class="hljs-keyword">RUN</span><span class="bash"> apt-get update -qq &amp;&amp; apt-get install -y nodejs</span>

<span class="hljs-keyword">ENTRYPOINT</span><span class="bash"> [ <span class="hljs-string">"/bin/bash"</span> ]</span>
</code></pre>
<ul>
<li><code>FROM ruby</code> - this means docker will pull a pre-built setup by ruby. You don't need to think about updating or installing on your machine the latest ruby version. You'll see the list of Docker's pre-built images <a target="_blank" href="https://hub.docker.com/">on their Dockerhub</a>. Think of it as like npm.</li>
<li><code>WORKDIR /home/app</code> - Work directory. Work directory means this is be your default folder location when you start your development environment. You can name it whatever you want.</li>
<li><code>ENV PORT 3000</code> - Environment variable. This will set a variable named <code>$PORT</code> on your bash terminal to be '3000'.</li>
<li><code>EXPOSE $PORT</code> - expose port 3000 (that we've set earlier) of the virtual container to your local machine.</li>
<li><code>RUN</code> - Run commands are some setup instructions that you want the terminal to run before you use it. In our case, we installed ruby on rails, bundler, and node.js before we even use the development environment so it's all ready when we use it.</li>
<li><code>ENTRYPOINT ["/bin/bash"]</code>- this command tells docker what command to execute when we run the container. In our case, we need to run bash terminal so we can have access to rails.</li>
</ul>
<p>Note that these explanations are only brief. You can see more explanations or you can do your deep-dive on <a target="_blank" href="https://docs.docker.com/engine/reference/builder/">Dockerfile reference docs</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-141.png" alt="Image" width="600" height="400" loading="lazy">
<em>Your Dockerfile will look like something like this.</em></p>
<p>You can do sorts of cool stuff with Dockerfile. In my case, I've tried to install zsh and <a target="_blank" href="https://github.com/robbyrussell/oh-my-zsh">oh-my-zsh</a> on my container because it has some cool auto-completion features. But in our example we don't really need it, it will only increase our image size, so I didn't include it.</p>
<h3 id="heading-4-make-a-file-named-docker-composeyml">4. Make a file named <code>docker-compose.yml</code></h3>
<p>Docker compose file is a file that ties up different services together. A good example is when you're wiring up your rails app to different servers like MySQL database server, or redis caching server. You can easily make them work with this file. But for our case, we'll stick to the minimum setup for clarity purposes. A YAML file is a type of markdown file with different rules on how to format your file. Just think of it as a JSON file, without the braces. Put this in your <code>docker-compose.yml</code> file.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">"3.7"</span>

<span class="hljs-attr">services:</span>
  <span class="hljs-attr">ruby_dev:</span>
    <span class="hljs-attr">build:</span> <span class="hljs-string">.</span>
    <span class="hljs-attr">container_name:</span> <span class="hljs-string">ruby_container</span>
    <span class="hljs-attr">ports:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">"3000:3000"</span>
    <span class="hljs-attr">volumes:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">./:/home/app</span>
</code></pre>
<p>As you can see, it kinda looks like the Dockerfile, but with a little bit of indentation. Let's go through the lines.</p>
<ul>
<li><code>version</code> - Through time, docker-compose file went through changes. That's why in docker-compose files, they need to specify which version they are using. In our case we just use the latest version as of this time.</li>
<li><code>services</code> - Specify list of services. As I said earlier, you can have many services like a rails server, and a MySQL server on your project. You can name your services any name you want. I named it <code>ruby_dev</code>.</li>
<li><code>build: .</code> - The dot here means a file path where to find the Dockerfile, which is the build instructions.</li>
<li><code>container_name</code> - The name of the container. </li>
<li><code>ports:</code> - these are the ports to expose from the docker container to our host local machine. The pattern here is <code>HOST:CONTAINER</code>. In our case it's "3000:3000". Which means we are letting the default Rails server port (3000) be available in our local machine's "localhost:3000".</li>
<li><code>volumes:</code> - volume means even if we quit or delete Docker, we can specify which files we can keep in our local machine. We put <code>./:/home/app</code> there because we named in our Dockerfile earlier the workdir to be <code>/home/app</code>.</li>
</ul>
<p>You can see more explanations on <a target="_blank" href="https://docs.docker.com/compose/compose-file/">Docker Compose reference docs</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-142.png" alt="Image" width="600" height="400" loading="lazy">
<em>Your docker-compose.yml will look like something like this.</em></p>
<h2 id="heading-building-and-running-the-container">Building and running the container</h2>
<p>With all our config files setup, let's build and run the container! After the loads of terms we encountered, building and running the container is way simpler. It will only involve few commands.</p>
<h3 id="heading-5-in-your-terminal-run-docker-compose-build">5. In your terminal, run <code>docker-compose build</code></h3>
<p>Running this command will get Dockerfile and install all the necessary things to make a rails development environment. Note that the installation may take a while because docker will need to download the necessary packages.</p>
<h3 id="heading-6-in-your-terminal-run-docker-compose-run-rm-service-ports-rubydev">6. In your terminal, run <code>docker-compose run --rm --service-ports ruby_dev</code></h3>
<p>This command will start a bash terminal that will be your rails development environment where the rails commands are available. With only these two commands, and two config files, you already have a rails environment without even going through a log of troubleshooting! Notice that our command has some flags, <code>--rm</code> means remove the container after using it, and <code>--service-ports</code> means use port 3000 in our container so we can see our rails server in action. The name <code>ruby_dev</code> also came from services found at our docker-compose.yml.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-143.png" alt="Image" width="600" height="400" loading="lazy">
<em>Your terminal might look like this after running the run command. Check if there's rails by running <code>rails -v</code> command. Versions might vary.</em></p>
<h2 id="heading-test-run-a-rails-app">Test-run a rails app</h2>
<p>Now that we've successfully made our rails development environment, we'll test a sample rails app. </p>
<h3 id="heading-1-run-rails-new-myapp-ampamp-cd-myapp">1. Run <code>rails new myapp &amp;&amp; cd myapp</code></h3>
<p>This command will create a new rails app in a folder named myapp. After that the terminal will go the folder. You can name it whatever you want.</p>
<h3 id="heading-2-update-and-install-gems-run-bundle-update-ampamp-bundle-install">2. Update and install gems. Run <code>bundle update &amp;&amp; bundle install</code></h3>
<p>Just make sure you're in the right folder, in <code>myapp</code>, which contains the rails app files. This command will update and install your dependencies.</p>
<h3 id="heading-3-test-the-server-by-running-rails-server-p-port-b-0000">3. Test the server by running <code>rails server -p $PORT -b 0.0.0.0</code></h3>
<p>Remember the port we specified in our Dockerfile before? This is where we can use it. In our case, rails will use port 3000 to start the server. Don't forget to put <code>-b 0.0.0.0</code> because you won't see the app on your local machine without this.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-144.png" alt="Image" width="600" height="400" loading="lazy">
<em>Hello rails splash screen. Yeah rails!!!</em></p>
<h3 id="heading-4-stop-the-server-by-pressing-ctrl-d-on-your-keyboard">4. Stop the server by pressing <code>ctrl-d</code> on your keyboard.</h3>
<h2 id="heading-cleaning-up">Cleaning Up</h2>
<p>After you're done with everything, you can exit on your container by running <code>exit</code> on your container's bash terminal. The <code>--rm</code> flag you typed before will remove the container, but will you get to keep your ruby on rails files.</p>
<h3 id="heading-run-docker-compose-down-to-cleanup">Run <code>docker-compose down</code> to cleanup</h3>
<p>Cleaning up is when you're done with the project, and you want to remove your dev environment so you can save space. If you're really done, you can use this command. Docker will remove all your setup, and the images you downloaded. This so powerful, because, imagine you followed a lot of steps and a lot of installation on your mac. The only way to remove that setup is to uninstall them one by one. With docker on our side, it's just one command. Aww yeah!</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Glad you made this far! Let's look at the big picture. Setting up a dev environment in Docker can be broken down in 2 steps:</p>
<ol>
<li>List the instructions you need on your Dockerfile and docker-compose file.</li>
<li>Start or stop or cleanup your dev environment with the <code>docker-compose</code> command.</li>
</ol>
<p>This is a big win for us. You just need to keep the Dockerfile and compose file and whenever you switch machines, you just run two commands! Setup once, and forget.</p>
<h3 id="heading-repository">Repository</h3>
<p>You can see the repository on how the setup looks like, and additional commands that you need here by checking out the <a target="_blank" href="https://github.com/jcunanan05/rails-docker">full github repo here.</a></p>
<p>If you find the article helpful, or if you have some additional questions, throw it in the comments. I'll be glad to help!</p>
<p>This article was written by Jonathan Cunanan on <a target="_blank" href="https://www.freecodecamp.org/news/painless-rails-development-environment-setup-with-docker/">freeCodeCamp News</a>.</p>
<p><a target="_blank" href="https://twitter.com/devJonathanC_">? Twitter</a> - <a target="_blank" href="https://www.freecodecamp.org/jcunanan05">? freeCodeCamp</a> -  <a target="_blank" href="https://jonathancunanan.com">? Portfolio</a> - <a target="_blank" href="https://github.com/jcunanan05">⚛️ Github</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What happens when you create a new Rails project ]]>
                </title>
                <description>
                    <![CDATA[ By Travis Fantina The first time you open your terminal and write rails new the sheer number of files and folders that are created can be overwhelming. You may even work on numerous Rails projects without ever opening many of these folders - so what ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-happens-when-you-run-rails-new/</link>
                <guid isPermaLink="false">66d852b629e30bc0ad4775bc</guid>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 08 Aug 2019 01:12:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9ca107740569d1a4ca4c41.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Travis Fantina</p>
<p>The first time you open your terminal and write <code>rails new</code> the sheer number of files and folders that are created can be overwhelming. You may even work on numerous Rails projects without ever opening many of these folders - so what exactly are they? What are they doing behind the scenes? </p>
<p>Well, the truth is that you don’t need many of them and Rails has several flags built into the <code>new</code> command which will allow you to create a new project without some of the built-in defaults of Rails (to learn more just type out <code>rails new —help</code>). That said, for most projects you’ll be running <code>rails new</code> and creating a beastly project folder. </p>
<p>In this post I’m going to go through every single file and folder in a new Rails 6 project. Feel free to use this as a reference as you are working through your new Rails project to understand some of the more obscure folders. Bookmark this post and return to it anytime you find yourself in the weeds on a new Rails project.</p>
<p>So let's start:</p>
<p><code>rails new example-project</code></p>
<p>Wow, that’s a lot!</p>
<p>First, Rails is creating all the files and folders required by a new Rails app.<br>Then it’s fetching gems and bundling them; these are the dependencies that Rails needs in order to run your website in its simplest iteration. Seem like a lot? To some extent it is but these gems add the functionality that makes a Rails project so easy to get off the ground. Essentially all you need to do now is run <code>rails server</code> and you have a webapp running locally: that’s pretty powerful and not something you can get so easily /without/ all that boilerplate.</p>
<p>Let's get into all those folders:</p>
<pre><code class="lang-shell">  create README.md
   create Rakefile
   create .ruby-version
   create config.ru
   create .gitignore
   create Gemfile
     run git init from "."
Initialized empty Git repository in /Users/tfantina/Documents/Code/FileStructure/.git/
   create package.json
   create app
   create app/assets/config/manifest.js
   create app/assets/stylesheets/application.css
   create app/channels/application_cable/channel.rb
   create app/channels/application_cable/connection.rb
   create app/controllers/application_controller.rb
   create app/helpers/application_helper.rb
   create app/javascript/channels/consumer.js
   create app/javascript/channels/index.js
   create app/javascript/packs/application.js
   create app/jobs/application_job.rb
   create app/mailers/application_mailer.rb
   create app/models/application_record.rb
   create app/views/layouts/application.html.erb
   create app/views/layouts/mailer.html.erb
   create app/views/layouts/mailer.text.erb
   create app/assets/images/.keep
   create app/controllers/concerns/.keep
   create app/models/concerns/.keep
   create bin
   create bin/rails
   create bin/rake
   create bin/setup
   create bin/yarn
   create config
   create config/routes.rb
   create config/application.rb
   create config/environment.rb
   create config/cable.yml
   create config/puma.rb
   create config/spring.rb
   create config/storage.yml
   create config/environments
   create config/environments/development.rb
   create config/environments/production.rb
   create config/environments/test.rb
   create config/initializers
   create config/initializers/application_controller_renderer.rb
   create config/initializers/assets.rb
   create config/initializers/backtrace_silencers.rb
   create config/initializers/content_security_policy.rb
   create config/initializers/cookies_serializer.rb
   create config/initializers/cors.rb
   create config/initializers/filter_parameter_logging.rb
   create config/initializers/inflections.rb
   create config/initializers/mime_types.rb
   create config/initializers/new_framework_defaults_6_0.rb
   create config/initializers/wrap_parameters.rb
   create config/locales
   create config/locales/en.yml
   create config/master.key
   append .gitignore
   create config/boot.rb
   create config/database.yml
   create db
   create db/seeds.rb
   create lib
   create lib/tasks
   create lib/tasks/.keep
   create lib/assets
   create lib/assets/.keep
   create log
   create log/.keep
   create public
   create public/404.html
   create public/422.html
   create public/500.html
   create public/apple-touch-icon-precomposed.png
   create public/apple-touch-icon.png
   create public/favicon.ico
   create public/robots.txt
   create tmp
   create tmp/.keep
   create tmp/cache
   create tmp/cache/assets
   create vendor
   create vendor/.keep
   create test/fixtures
   create test/fixtures/.keep
   create test/fixtures/files
   create test/fixtures/files/.keep
   create test/controllers
   create test/controllers/.keep
   create test/mailers
   create test/mailers/.keep
   create test/models
   create test/models/.keep
   create test/helpers
   create test/helpers/.keep
   create test/integration
   create test/integration/.keep
   create test/channels/application_cable/connection_test.rb
   create test/test_helper.rb
   create test/system
   create test/system/.keep
   create test/application_system_test_case.rb
   create storage
   create storage/.keep
   create tmp/storage
   create tmp/storage/.keep
</code></pre>
<p>Let's jump in:</p>
<pre><code>cd example-project
code .
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2019/08/0DE7CF47-259B-4346-8FB4-DEE2EE74709B.png" alt="Image" width="600" height="400" loading="lazy">
<em>In VSCode this is what we have</em></p>
<p>We will go in order as Rails organizes them, for the most part, I will be talking about every single folder and file, for repeated files (such as .keep) I will only mention it once.  You will notice a lot of conventions in Rails such as “application_[framework]s” (<code>application_controller.rb</code>, <code>application_helper.rb</code>, <code>application_job.rb</code> etc).  In such instances I will cover the folder in detail so you know what goes inside, just know that the existing file “application_[...].rb” is a parent class that other classes you create in the folder will inherit from.</p>
<h1 id="heading-the-app-folder">The app folder</h1>
<p>Is where the majority of your development work will take place /app contains the Models, Views, and Controllers that will be served to users when requested by the browser.</p>
<h3 id="heading-appassets">app/assets</h3>
<p>Stores assets for the Rails Asset Pipeline. The Asset Pipeline brings together the assets (JavaScript, CSS, and images), in a project and serves them to the client in the most efficient way possible. It does this by concatenating and minifying assets. It also precompiles assets written in Sass and CoffeeScript.<br>More info: <a target="_blank" href="https://guides.rubyonrails.org/asset_pipeline.html">The Asset Pipeline — Ruby on Rails Guides</a></p>
<h3 id="heading-appassetsconfig">app/assets/config</h3>
<p>See below</p>
<h4 id="heading-appassetsconfigmanifestjs">app/assets/config/manifest.js</h4>
<p>The aforementioned Asset Pipeline is managed by a Ruby gem called “Sprockets-rails” which does all of the above. “Sprockets-rails” has some associated helper gems such as “sass-rails”, “uglifier” and “coffee-rails”. Coffee-rails and Sass-rails precompile your Sass and CoffeeScript into CSS and JavaScript while Uglifier minifies these assets.  Manifest.js lets you specifically set what is going to get pre-compiled.<br>For more on this specific file see: <a target="_blank" href="https://eileencodes.com/posts/the-sprockets-4-manifest/">eileen.codes | Rails 5: The Sprockets 4 Manifest</a></p>
<h3 id="heading-appassetsimages">app/assets/images</h3>
<p>Image assets, such as icons and SVGs for the Asset Pipeline can be placed here.</p>
<h4 id="heading-keep">.keep</h4>
<p>This is the first of many .keep files you will see throughout a new Rails project. These are not Rails files but files for Git which won’t normally track empty folders. The keep. file just says “someone’s in here”. Anything with a .keep file will be tracked by Git. You don’t need .keep if you put something else in the folder.</p>
<h3 id="heading-appassetsstylesheets">app/assets/stylesheets</h3>
<p>The stylesheets folder is where you will place styles associated with your app. You can write stylesheets in CSS or SASS out of the box., the Asset Pipeline will precompile any and all stylesheets for you.</p>
<h4 id="heading-appassetsstylesheetsapplicationcss">app/assets/stylesheets/application.css</h4>
<p>Contains all styles that will be included in the Asset Pipeline.  Global styles can be written in Application.css but you can also write Controller specific stylesheets (when you run the command <code>rails g</code>  to create a new Controller it will create an associated stylesheet.  <code>=require_tree .</code>  is Rails way of including all associated folders inside a directory so any other CSS files inside this project will be included when compiled <code>=require_self</code> will include any CSS that you write inside the Application.css file itself, this is location specific so the CSS inside Application.css will be run /after/ the other folders that are pulled in by <code>require_tree .</code></p>
<h2 id="heading-appchannels">.app/channels</h2>
<p>Rails has numerous smaller internal frameworks. ActionCable is a framework that lets you use WebSockets to create realtime features in your app like chats and auto-updating “subscriptions” to notifications and new content. If you are not going to implement any realtime features you don’t need to worry about any ActionCable folders. The channels folder holds the server-side Ruby files for creating these connections.<br>You can read all about ActionCable here: <a target="_blank" href="https://guides.rubyonrails.org/action_cable_overview.html">Action Cable Overview — Ruby on Rails Guides</a></p>
<h3 id="heading-appchannelsapplicationcable">app/channels/application_cable</h3>
<p>Application_cable holds channel and connection files for creating new realtime features in your app.</p>
<h4 id="heading-appchannelsapplicationcablechannelrb">app/channels/application_cable/channel.rb</h4>
<p>Each individual realtime features of your app would be encapsulated into an individual channel channel. For example, a chat feature chat, could be one channel. A notification system for newly published content would be a separate channel. This folder contains all the channels of your application.</p>
<h4 id="heading-appchannelsapplicationcableconnectionrb">app/channels/application_cable/connection.rb</h4>
<p>Connections are the authentication between the user and the server. They don’t deal with any logic (that’s what channels do), rather they just check to make sure the current user is authorized to subscribe to the various channels in your application. In most cases, this would be a simple verification that the user is logged in.</p>
<h2 id="heading-appcontrollers">app/controllers</h2>
<p>Part “C” of the “MVC” pattern in Model View Controllers. Controllers like a middleman between the model and the view. Based on the user’s request the Controller will grab any associated data from the Model and pass it to the view which the user is shown. For example, if a user is navigating to the localhost:3000/posts page the Controller will determine what View they are shown as well as any associated records from the Model.</p>
<h3 id="heading-appcontrollersconcerns">app/controllers/concerns</h3>
<p>Concerns are a way to shrink your Models down, rather than writing a huge amount of reusable methods in a single model you can throw those methods into concerns where they can be easily reused in your Controllers.</p>
<h3 id="heading-appcontrollersapplicationcontrollerrb">app/controllers/application_controller.rb</h3>
<p>Controllers are just ruby classes that inherit from a class called ActionController. As you add more models to your project you will have more controllers to deal with. application<em>controller.rb is required for any Rails project because it inherits from <code>ActionController::Base</code> and all future controllers intern inherit from it, giving them the functionality of Controllers.<br>You’ll see a lot of “application</em>[insert relative title here].rb” files: application_controller.rb, application_helper.rb, application_record.rb. In most cases, these represent a global way of interacting with the app, an intermediary that inherits from a base class and then is inherited by future classes or both. I won’t discuss the functions of these files in all cases.</p>
<h2 id="heading-apphelpers">app/helpers</h2>
<p>Helpers are a way to keep your views tidy. Views should be concerned simply with displaying information as html to the user. If you find your html.erb files are getting bogged down with lots of little calculations or logic you should move that code into helper methods.</p>
<h3 id="heading-apphelpersapplicationhelperrb">app/helpers/application_helper.rb</h3>
<p>Provides a place to write global helpers, as you create more Controllers you will have more helpers to work with specific Controllers and Views.</p>
<h2 id="heading-appjavascript">app/javascript</h2>
<p>This folder is a handy place to put all the javascript you use in your application, the Rails Asset Pipeline will include them from this folder into any pages where they apply (the Asset Pipeline knows where the scripts belong because the files, normally, follow a naming convention of the Controller they apply too).</p>
<h3 id="heading-appjavascriptchannels">app/javascript/channels</h3>
<p>We’ve already looked at ActionCable’s channels above but this folder contains client-side specific javascript for creating realtime WebSocket connections.</p>
<h4 id="heading-appjavascriptchannelsconsumerjs">app/javascript/channels/consumer.js</h4>
<p>Consumers are the clients of a WebSocket connection; the end-users who are subscribing to the channel. This script will connect those consumers to the channel on the client-side.</p>
<h4 id="heading-appjavascriptchannelsindexjs">app/javascript/channels/index.js</h4>
<p>An application can have multiple Channels (chat, alerts, new posts, etc). index.js is a client-side directory of all the channels in your application.</p>
<h4 id="heading-appjavascriptpacksapplicationjs">app/javascript/packs/application.js</h4>
<p>Webpacker is a ruby gem which allows you to use Webpack, the JavaScript bundler in your Rails project. It works in conjunction with the Asset Pipeline and is intended for large JavaScript frameworks, not small scripts or other assets like CSS or images (which Webpack generally would handle in a Javascript project).  Webpacker, however, is flexible and this is just the default. You can have Webpack handle images and smaller JavaScripts completely bypassing the Asset Pipeline if you’d like. You can specify that in this folder by requiring different assets. The default assets that get packed are:</p>
<pre><code class="lang-js">*<span class="hljs-built_in">require</span>(<span class="hljs-string">"@rails/ujs"</span>).start()*
*<span class="hljs-built_in">require</span>(<span class="hljs-string">"turbolinks"</span>).start()*
*<span class="hljs-built_in">require</span>(<span class="hljs-string">"@rails/activestorage"</span>).start()*
*<span class="hljs-built_in">require</span>(<span class="hljs-string">"channels"</span>)*
</code></pre>
<h3 id="heading-appjobs">app/jobs</h3>
<p>Jobs are background tasks that you run while users continue to use your application Any time you have an operation that will involve a lot of processing, enough to slow the user’s experience down significantly and cause your application to “hang”, you should create a background job that will run the task behind the scenes allowing the user to continue using your site uninterrupted.<br>For more info on Jobs see: <a target="_blank" href="https://blog.codeship.com/how-to-use-rails-active-job/">Rails Active Job Tutorial: How to Use activejob | Codeship | via @codeship</a></p>
<h4 id="heading-appassetsjobsapplicationjobrb">app/assets/jobs/application_job.rb</h4>
<p>See above.</p>
<h2 id="heading-appmailers">app/mailers</h2>
<p>You can think of mailers as controllers for emails. You can create a new mailer with <code>Rails generate mailer</code>. This will give you the equivalent of a Model and a Controller for sending emails to your users.</p>
<h3 id="heading-appmailersapplicationmailerrb">app/mailers/application_mailer.rb</h3>
<p>See above.</p>
<h2 id="heading-appmodels">app/models</h2>
<p>The “M” of MVC; a Model is a template for the data stored in your database. Generally, any table is considered a “Model”.  Common models may be  <code>User</code> ,  <code>Post</code>  or  <code>Comment</code> .  Note that these things are singular rather than plural, this is a reference to the prototypical nature of a model.  This is in contrast to Controllers why by convention are plural because Controllers are referencing multiple records.</p>
<h3 id="heading-appmodelsconcerns">app/models/concerns</h3>
<p>Concerns are modules - little nuggets of reusable code generally extracted from Models when they get too fat.  The Concerns folder is part of an internal Rails framework called ActiveSupport which makes modules a bit easier to manage.</p>
<p>For more info see the Rails <a target="_blank" href="https://api.rubyonrails.org/classes/ActiveSupport/Concern.html">guides on concerns</a>.</p>
<h3 id="heading-appmodelsapplicationrecordrb">app/models/application_record.rb</h3>
<p>Application_record.rb inherits from <code>ActiveRecord::Base</code> all subsequent models in your app will inherit from <code>ApplicationRecord</code> , similar to how Application_controller makes the functionality of the <code>ActionController</code> available to all other Controllers.</p>
<h2 id="heading-appviews">app/views</h2>
<p>The last piece of the MVC pattern is Views. The Views folder contains everything the user will see in their browser, mostly in the form of HTML with embedded Ruby (ERB) or .Haml which is a templating language for Ruby. New controllers will most likely have an associated view folder with the same name (unless you’re creating an API).  Generally speaking, every method in the Controller will have an associated View.</p>
<h3 id="heading-appviewslayouts">app/views/layouts</h3>
<p>Your new Rails app will have a Layouts folder with <strong>application.html.erb</strong>, <strong>mailer.html.erb</strong> and <strong>mailer.text.erb</strong> these set global layouts for the Rails app in various domains such as the browser and the inbox.  You may wish to add other components of a layout into this folder, for example, a <strong>_header.html.erb</strong> but most of your views will be organized into View folders specific to their Controller. <strong>Application.html.erb</strong> is the main template for your app, this file creates the main HTML <code>&lt;head&gt;</code> and <code>&lt;body&gt;</code> tags for your application with the views themselves shown in <code>&lt;%= yield %&gt;</code> . Yield is just a bit of Ruby code that adds the appropriate view for the page the user is looking at. Having an <strong>Application.html.erb</strong> file keeps your code DRY since you don’t have to repeatedly declare a doctype, head elements or include scripts and stylesheets, for every page in the View. Rails and the Asset Pipeline take care of this for you. The three files in this folder as stated above are:</p>
<ul>
<li>app/views/layouts/application.html.erb</li>
<li>app/views/layouts/mailer.html.erb</li>
<li>app/views/layouts/mailer.text.erb</li>
</ul>
<h1 id="heading-bin-folder">bin folder</h1>
<p>The bin folder helps set up the Rails application so it and associated commands can run properly.</p>
<h2 id="heading-binbundle">bin/bundle</h2>
<p>Ensures that the Gem Bundler works properly.</p>
<h2 id="heading-binrails">bin/rails</h2>
<p>Spring is a preloader which keeps Rails running in the background as you work (there are some cases where you need to restart the server but for the most part changes to the Views or Controllers will be loaded automatically and immediately into your app running in a development environment).  This file loads spring when you start the Rails application.</p>
<h2 id="heading-binrake">bin/rake</h2>
<p>Rake stands for Ruby Make and is used to run several commands that will both set up and update the server.</p>
<h2 id="heading-binsetup">bin/setup</h2>
<p>Lets you write commands that will run when your app is first started.</p>
<h2 id="heading-binspring">bin/spring</h2>
<p>Allows Spring to run without using the Bundler to bundle all your gems, this lets spring quickly reload your pages in development whenever you make a change.</p>
<h2 id="heading-binwebpack">bin/webpack</h2>
<p>As discussed above Rails uses Webpack for bundling some JavaScripts as opposed to the AssetPipeline, this file requires the necessary setup and then runs Webpack.</p>
<h2 id="heading-binwebpack-dev-server">bin/webpack-dev-server</h2>
<p>Allows you to customize the dev server of Webpack which you may wish to do if you don’t want some or all of your assets bundled in your development environment.</p>
<h2 id="heading-binyarn">bin/yarn</h2>
<p>Yarn is a JavaScript package manager similar to NPM.  You can use either with Rails projects.</p>
<h1 id="heading-config">config</h1>
<p>Config, much like the name implies contains files for setting up your Rails application in different environments; development and test.</p>
<h2 id="heading-configenvironments">config/environments</h2>
<p>This folder lets you configure how your application will work in development, production and testing environments. For example, you may wish to ensure that your action_mail is configured to send emails through a mail service in production but not in development.</p>
<h2 id="heading-configinitializers">config/initializers</h2>
<p>This folder allows you to set granular initializers to define how your Rails app will preform there is a good chance you won’t spend too much time in here especially when working on your first few Rails applications.</p>
<h3 id="heading-configinitializersapplicationcontrollerrendererrb">config/initializers/application_controller_renderer.rb</h3>
<p>Allows controllers to render outside their scope. For more information see: <a target="_blank" href="https://mensfeld.pl/2015/12/upgrading-to-ruby-on-rails-5-0-from-rails-4-2-application-use-case/">Upgrading to Ruby on Rails 5.0 from Rails 4.2 - application use case - Running with Ruby</a></p>
<h3 id="heading-configinitializersassetsrb">config/initializers/assets.rb</h3>
<p>Relates to the Asset Pipeline; which, you’ll remember, serves pages in your Rails app with the specific assets (CSS, JS, etc) they need. Here, you can add assets to the load path such as node_modules.</p>
<h3 id="heading-configinitializers-backtracesilencersrb">config/initializers/ backtrace_silencers.rb</h3>
<p>Backtraces are a debugging tool that allows you to see what’s going on in your Rails app, particularly useful when things blow up and you can pinpoint the specific area of failure. Configure what backtraces show by determining which libraries are allowed to show backtraces in this file.</p>
<h3 id="heading-configinitializerscontentsecuritypolicyrb">config/initializers/content_security_policy.rb</h3>
<p>From Mozilla: “The HTTP <em>Content-Security-Policy</em> response header allows web site administrators to control resources the user agent is allowed to load for a given page. With a few exceptions, policies mostly involve specifying server origins and script endpoints.“ <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy">Content-Security-Policy - HTTP | MDN</a>. In essence, this controls the data that is allowed to flow into your app and from what external sources. For example linking to external scripts, fonts or images outside of your app.</p>
<h3 id="heading-configinitializerscookiesserializerrb">config/initializers/cookies_serializer.rb</h3>
<p>Determines the format for cookies, by default this is <code>:json</code></p>
<h3 id="heading-configinitializersfilterparameterloggingrb">config/initializers/filter_parameter_logging.rb</h3>
<p>We’ll discuss logging below but there are some parameters (accepted user inputs) like passwords or sensitive user data that you don’t want to show up in your log, you can add them here. filter_paramiter_logging is sort of like .gitignore for parameters.</p>
<h3 id="heading-configinitializersinflectionsrb">config/initializers/inflections.rb</h3>
<p>As discussed in the Model explanation, Rails has naming conventions for what is singular and plural. Based on locales (language settings for your app see Locales folder below) you can update these inflections in this initializer although it’s probably not a good idea unless it’s absolutely necessary.</p>
<h3 id="heading-configinitializersmimetypesrb">config/initializers/mime_types.rb</h3>
<p>MIME types - Multipurpose Internet Mail Extensions specify the format of email attachments.<br><a target="_blank" href="https://en.wikipedia.org/wiki/MIME">MIME - Wikipedia</a></p>
<h3 id="heading-configinitializerswrapparametersrb">config/initializers/wrap_parameters.rb</h3>
<p>By default, Rails wraps all parameters into JSON but you can specify other formats using the <code>wrap_parameters</code> hash. <a target="_blank" href="https://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html">ActionController::ParamsWrapper</a></p>
<h2 id="heading-configlocales">config/locales</h2>
<p>Will generally load with en.yml as the only file. If your application is going to have multiple language options you can include all the translations as YML files here.</p>
<h2 id="heading-configwebpack">config/webpack</h2>
<pre><code>Allows you to configure Webpack settings based on the environment.
</code></pre><h3 id="heading-configwebpackdevelopmentjs">config/webpack/development.js</h3>
<h3 id="heading-configwebpackenvironmentjs">config/webpack/environment.js</h3>
<h3 id="heading-configwebpackproductionjs">config/webpack/production.js</h3>
<h3 id="heading-configwebpacktestjs">config/webpack/test.js</h3>
<h3 id="heading-configapplicationrb">config/application.rb</h3>
<p>Will run the boot.rb file if you are using Passenger.  It pulls all gems you’ve required in the gem file into your project and creates a class <code>Application</code> that inherits from <code>Rails::Application</code></p>
<h2 id="heading-configbootrb">config/boot.rb</h2>
<p>Creates an environment variable <code>BUNDLE_GEMFILE</code> set to the location of your project’s gem file, this is how Rails will know where to pull in dependencies or Gems, of which there are about 2 dozen in an out-of-the-box Rails install.</p>
<h2 id="heading-configcableyml">config/cable.yml</h2>
<p>Similar to database.yml (see below) cable.yml sets development, test and production adapters for ActionCable, which you will remember is Rails way of implementing realtime features into your application.</p>
<h2 id="heading-configcredentialsymlenc">config/credentials.yml.enc</h2>
<p>credentials.yml replaces secrets.yml as the location of secret keys. This file is encrypted so nobody can read your secret keys and is only decrypted by the master key (see below).</p>
<h2 id="heading-configdatabaseyml">config/database.yml</h2>
<p>You can set a default database (to make your code a little DRYer) as well as specific DBs for development, test, and production.</p>
<h2 id="heading-configenvironmentrb">config/environment.rb</h2>
<p>Initializing the Rails application on the server requires a lot of steps, depending on if you’re using <code>rails server</code> or Passenger these steps may be slightly different but once environment.rb loads the application is initialized and begins running.</p>
<h2 id="heading-configmasterkey">config/master.key</h2>
<p>Throw this into your .gitignore file right away (see below), this is the master key that decrypts credentials.yml.enc in Rails and nobody should have it. For more info you can read this brilliant article: <a target="_blank" href="https://medium.com/cedarcode/rails-5-2-credentials-9b3324851336">Rails 5.2 credentials – cedarcode – Medium</a></p>
<h2 id="heading-configpumarb">config/puma.rb</h2>
<p>Puma is a web server for Ruby and is the default web server for Rails’ development environment. You can configure Puma through this folder altering things like thread count and the default port that puma will listen for incoming requests on (default is 3000).</p>
<h2 id="heading-configroutesrb">config/routes.rb</h2>
<p>Routes are the road map around your Controllers. Routes take incoming requests to the server and direct them to the correct Controller.  Unlike most other files in the config folder, you will spend a lot of time here setting up routes as you build your app.</p>
<h2 id="heading-configspringrb">config/spring.rb</h2>
<p>As discussed in the bin folder Spring is a preloader this file actually tells Spring which files and folders should trigger a restart.</p>
<h2 id="heading-configstorageyml">config/storage.yml</h2>
<p>ActiveStorage is a framework introduced in Rails 5.2 for uploading and storing assets such as images. You need a place to put those things such as an AWS instance, you specify that location in this file.</p>
<h2 id="heading-configwebpackeryml">config/webpacker.yml</h2>
<p>Allows you to add additional environments too Webpacker.</p>
<h1 id="heading-db">db</h1>
<h2 id="heading-dbseeds">db/seeds</h2>
<p>Seeds let you fill a database with data. Let’s say you wanted to see your pagination feature in action; you could create 11 posts by hand or you could just use a gem such as Faker to create 11 random posts for you and insert them directly into your database.</p>
<h2 id="heading-lib">lib</h2>
<p>Lib is defined by Rails guides as “Extended modules for your application.” If this sounds vague you're not the only one who feels that way. What specifically goes in the lib folder is somewhat controversial: see <a target="_blank" href="https://medium.com/extreme-programming/what-goes-in-rails-lib-92c74dfd955e">What goes in Rails lib/ – Extreme Programming – Medium</a> and <a target="_blank" href="https://codeclimate.com/blog/what-code-goes-in-the-lib-directory/">What code goes in the lib/ directory?</a> but the general consensus is that lib should be reserved for code that does not fit into the app folder, that could be easily extracted out for use in other applications. It has two subfolders assets and tasks</p>
<h2 id="heading-libassets">lib/assets</h2>
<p>From Ruby on Rails Guides: </p>
<blockquote>
<p>"lib/assets is for your own libraries’ code that doesn’t really fit into the scope of the application or those libraries which are shared across applications."</p>
</blockquote>
<h2 id="heading-libtasks">lib/tasks</h2>
<p>You can write custom <code>rake</code> tasks and put them in this folder.  It's not a very commonly used location.</p>
<h1 id="heading-log">log</h1>
<p>Logging is an important way to see how your application is performing and for finding and troubleshooting issues. By default, this folder will be empty. You can initialize various loggers in the config/environments folder with a command like: <code>config.log_level = :info</code> from there as you’re run your application the Log file will be created.  For more detailed info see this great article from Datadog: <a target="_blank" href="https://www.datadoghq.com/blog/managing-rails-application-logs/">How to collect, customize, and manage Rails application logs</a></p>
<p>Included in the Log folder:</p>
<ul>
<li>log/development.log</li>
</ul>
<h1 id="heading-nodemodules">node_modules</h1>
<p>Any node packages you are using in your project (such as Webpack and Babel) will be dependant on dozens if not hundreds of other node packages. A package manager such as NPM or Yarn will manage these packages for you. You shouldn’t go into this folder or edit anything in it.</p>
<h1 id="heading-public">public</h1>
<p>The public folder contains resources that are external and may be accessed outside the normal structure of your application, favicon, apple-touch-icons, robots.txt and of course error pages. Pages like: 404, 422 and 500. Should the application in production experience some kind of error these HTML pages will be served automatically bypassing routes, controllers or any specific views. These pages are not part of the Rails Asset Pipeline so you will need to write any styles inline.</p>
<h2 id="heading-publicrobotstxt">public/robots.txt</h2>
<p>Allows you to specify how search engines crawl your website.</p>
<h1 id="heading-storage">storage</h1>
<p>Rails 5.2 introduced ActiveStorage which replaced gems like PaperClip and allows Rails to directly interface with cloud services like AWS or Google</p>
<h1 id="heading-test">test</h1>
<p>Rails has testing built-in from the ground up! The default test suite in Rails is MiniTest so you will find that all these folders are ready to go with MiniTest.<br>There are folders where you can test specific Controllers, Helpers, Models, Mailers as well as write Integration tests which work across multiple Controllers and recreate something akin to actual user experience. For more on what a constitutes a controller test vs an integration test I recommend this article from (<a target="_blank" href="https://www.codewithjason.com/difference-integration-tests-controller-tests-rails/">Jason Swett</a>)</p>
<h2 id="heading-testchannels">test/channels</h2>
<h4 id="heading-testchannelsapplicationcableconnectiontestrb">test/channels/application_cable/connection_test.rb</h4>
<p>Tests for ActionCable connections like all ActionCable stuff you will only need this if you are using channels in your application.</p>
<h2 id="heading-testcontrollers">test/controllers</h2>
<p>You can test your controllers here, these tests are generally looking at how well your controller goes between the model and the view, they are larger in scope then Model tests but smaller in scope then Integration tests.</p>
<h2 id="heading-testfixtures">test/fixtures</h2>
<p>Not a place for writing tests but generating dummy test data. Inside the fixtures folder you can add any number of YML files with predefined data. You can pull this data into your tests to make sure that your models are working correctly and interacting with the application as expected.</p>
<h3 id="heading-testfixturesfiles">test/fixtures/files</h3>
<p>Now that Rails has file handling built-in with ActiveStorage not only can you test data from models you can also test files.</p>
<h2 id="heading-testhelpers">test/helpers</h2>
<p>You can write specific tests for the helpers you have in app/helpers. Testing helpers is not too common but you can do it if a helper is overly complex or seems brittle.</p>
<h2 id="heading-testintegration">test/integration</h2>
<p>Integration tests allow you to test interactions between controllers and provide a testing option closer to the actual user experience.</p>
<h2 id="heading-testmailers">test/mailers</h2>
<p>You can even write tests for your mailers, to ensure emails are being sent correctly and formatted properly.</p>
<h2 id="heading-testmodels">test/models</h2>
<p>One of the most granular tests; you can ensure that a record is saved properly, the database has updated, etc.</p>
<h2 id="heading-testsystem">test/system</h2>
<p>System tests are a way of testing your application in a real browser generating screenshots to show you how everything looks in action.  System tests will also test the JavaScript, not that you should use MiniTest system tests as a replacement for a good JavaScript testing library like Jest. System tests; however, will allow you to see how your JavaScript is functioning in the browser.</p>
<h2 id="heading-testapplicationsystemtestcaserb">test/application_system_test_case.rb</h2>
<p>This file holds the defaults for your system tests, you can change browsers, drivers or screen resolution.</p>
<h2 id="heading-testtesthelperrb">test/test_helper.rb</h2>
<p>Test helper brings in external data and libraries that are required for tests. You will notice that right off the bat <code>fixtures :all</code> is imported. This gives your tests access to fixtures. You could set up a host of other test suites and frameworks from test_helper.rb to include their functions and DSLs such as Capybara, FactoryBot and Faker.</p>
<h1 id="heading-tmp">tmp</h1>
<p>Temporary - this folder contains caches and sessions it may be cleared on occasion either manually or on deploy (depending on how you are deploying your app).</p>
<h1 id="heading-vendor">vendor</h1>
<p>The vendor folder is a place for 3rd party code somewhat like Gems. Gems; however, are a bit more self-contained whereas the vendor folder may contain specific scripts not bundled as gems.  For more on this as well as some of the benefits see <a target="_blank" href="http://fuzzyblog.io/blog/ruby/2014/08/22/how-to-vendor-gem-a-gem.html">How to Vendor Gem a Gem</a>.</p>
<h1 id="heading-browserslistrc">.browserslistrc</h1>
<p>Browserslist is a tool to target specific browser versions for NPM tools such as Babel. Set to “defaults” by default, ensures that</p>
<h1 id="heading-gitignore">.gitignore</h1>
<p>As with any other project, your version control will ignore any files or folders you specify in here.</p>
<h1 id="heading-ruby-version">.ruby-version</h1>
<p>Simply contains the version of Ruby the project is working under, RVM can read this file and set the correct version of ruby on your computer (if you have multiple versions of Ruby installed).</p>
<h1 id="heading-babelconfigjs">babel.config.js</h1>
<p>Babel is a JavaScript compiler that lets you use the latest and greatest features of JavaScript and compiles them to be compatible with web browsers that may not yet have adopted those features. For more information on Babel configuration see their <a target="_blank" href="https://babeljs.io/docs/en/">official docs.</a></p>
<h1 id="heading-configru">config.ru</h1>
<p>Rack (the popular Ruby server) uses this file to start the application.</p>
<h1 id="heading-gemfile">gemfile</h1>
<p>Inside the gemfile you store all your application’s dependencies, as you have seen the Rails New command installs a lot of gems but as you add more functionality to your application you’ll be hopping in and out of this file a lot.</p>
<h1 id="heading-gemfilelock">gemfile.lock</h1>
<p>Similar to package-lock.json for Node projects, this file is updated when you run <code>bundle install</code> or <code>bundle update</code> and resolves all gem dependencies above and beyond what you included manually in the gem file. Don’t mess with this file it’s updated automatically.</p>
<h1 id="heading-packagejson">package.json</h1>
<p>Establishes NPM dependencies for Javascript modules, these will be packed with Webpacker.</p>
<h1 id="heading-postscssconfigjs">postscss.config.js</h1>
<p>PostCSS gives you a lot of modern functionality with CSS, from automatically adding vendor prefixes to including CSS Modules. For more on this cool tool check it out.</p>
<h1 id="heading-rakefile">rakefile</h1>
<p>Again Rake stands for “Ruby Make”. Rails has several commands built in which require Rake such as <code>rake routes</code> (showing you all routes for your application) <code>rake db:migrate</code> to add new Models and columns to your db. Among others, you can add custom rake commands here.</p>
<h1 id="heading-readmemd">README.md</h1>
<p>This is the Readme for your project, it will be displayed on your projects Github page, include any information you believe would be useful for others investigating or working with your project.</p>
<h1 id="heading-yarnlock">yarn.lock</h1>
<p>Much like package.json, Yarn is Webpacker default package manager. This is a lock file, so like Gemfile.lock it will be updated automatically and you should not change it manually.</p>
<p>You made it through! Congratulations!</p>
<p><div class="embed-wrapper"><iframe src="https://giphy.com/embed/LVWQ9iBwkpLmU" width="480" height="270" class="giphy-embed" title="Embedded content" loading="lazy"></iframe></div></p><p><a href="https://giphy.com/gifs/reactiongifs-LVWQ9iBwkpLmU">via GIPHY</a></p><p></p>
<hr>
<h1 id="heading-additional-resources">Additional Resources</h1>
<p>Helpers(<a target="_blank" href="https://mixandgo.com/learn/the-beginners-guide-to-rails-helpers">The Beginner’s Guide to Rails Helpers - Mix &amp; Go</a>)<br>Info on Keep Files (<a target="_blank" href="https://stackoverflow.com/questions/29183372/rails-why-is-there-keep-file-in-every-directory">StackOverflow keep files</a>)<br>Rails Initialization (<a target="_blank" href="https://guides.rubyonrails.org/initialization.html">The Rails Initialization Process — Ruby on Rails Guides</a>)<br>Creating the Blog Application(<a target="_blank" href="https://guides.rubyonrails.org/getting_started.html#creating-the-blog-application">Getting Started with Rails — Ruby on Rails Guides</a>)</p>
<hr>
<p>I realize that's pretty overwhelming but let me simplify it a bit. 99% of Rails is there to let you customize your project to the nth degree this is why Rails continues to work well for large enterprises and startups alike; you can easily adjust and tweak almost any part of your application with very little effort. That said, for most beginners, personal projects and even a decent amount of corporate projects you will use very little of this functionality.</p>
<p> Since Models, Views, and Controllers represent the core of a Rails application you will be spending most of your development time in the app folder. You will use the routes.rb file a fair amount in the config folder while you set up how users will step through your app and as you add new Controller actions. Be sure to always write proper test coverage for your applications. If you are, you will spend a lot of time in the test folder. The gemfile is one final place you will visit often adding and updating gems as needed.</p>
<p>Although there are a ton of files and folders created in every new <code>rails new</code> you shouldn’t be overwhelmed by it; if you ever get lost this post has your back.</p>
<p># </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Rails: How to set unique interchangeable index constraint ]]>
                </title>
                <description>
                    <![CDATA[ Setting uniqueness validation in rails is something you’ll end up doing quite often. Perhaps, you even already added them to most of your apps. However, this validation only gives a good user interface and experience. It informs the user of the error... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-set-unique-interchangeable-index-constraint-in-rails/</link>
                <guid isPermaLink="false">66bb8f9ad2bda3e4315491c6</guid>
                
                    <category>
                        <![CDATA[ database ]]>
                    </category>
                
                    <category>
                        <![CDATA[ postgres ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Saheed Oladele ]]>
                </dc:creator>
                <pubDate>Mon, 15 Jul 2019 10:50:49 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9ca178740569d1a4ca4ec3.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Setting uniqueness validation in rails is something you’ll end up doing quite often. Perhaps, you even already added them to most of your apps. However, this validation only gives a good user interface and experience. It informs the user of the errors preventing the data from being persisted in the database.</p>
<h3 id="heading-why-uniqueness-validation-is-not-enough">Why uniqueness validation is not enough</h3>
<p>Even with the uniqueness validation, unwanted data sometimes gets saved in the database. For clarity, let’s take a look at a user model shown below:</p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span></span>
    validates <span class="hljs-symbol">:username</span>, <span class="hljs-symbol">presence:</span> <span class="hljs-literal">true</span>, <span class="hljs-symbol">uniqueness:</span> <span class="hljs-literal">true</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>To validate the username column, rails queries the database using SELECT to see if the username already exists. If it does, it prints “Username already exists”. If it doesn’t, it runs an INSERT query to persist the new username in the database.  </p>
<p><img src="https://lh5.googleusercontent.com/BXp1jq7tCUcP9meYKOz4G8fL_2hcEKK5roipT6sH7wugLhIizTFov8q37QTDTF0mNJtgI0QQm8vbrXaKq9JIQVq1hzcnBYYDr_Fy2KO6mEAR4fBfJy9uWoJ3VUu_JNxUYa0_ELfm" alt="Image" width="1258" height="686" loading="lazy"></p>
<p>When two users are running the same process at the same time, the database can sometimes save the data regardless of the validation constraint and that is where the database constraints (unique index) comes in.</p>
<p>If user A and user B are both trying to persist the same username into the database at the same time, rails runs the SELECT query, if the username already exists, it informs both users. However, if the username doesn’t exist in the database, it runs the INSERT query for both users simultaneously as shown in the image below.</p>
<p><img src="https://lh3.googleusercontent.com/8-B6arsNFfdkLSkZbYt3F2KPPaFEbjAolPeDU9j3jMw3twF7r44uCum8dGNPGCduaLcX1E4n5QUTF4YUzPrPMI_QHyajoma8ULLyWo1aSYM5CJgu-1NEc3PDIuSpUFQvISE4Pu4y" alt="Image" width="1258" height="686" loading="lazy"></p>
<p>Now that you know why the database unique index (database constraint) is important, let’s get into how to set it. It’s quite easy to set database unique index(es) for any column or set of columns in rails. However, some database constraint in rails can be tricky.</p>
<h3 id="heading-a-quick-look-at-setting-a-unique-index-for-one-or-more-column">A quick look at setting a unique index for one or more column</h3>
<p>This is quite as simple as running a migration. Let’s assume we have a users table with column username and we want to ensure that each user has a unique username. You simply create a migration and input the following code:</p>
<pre><code class="lang-ruby">add_index <span class="hljs-symbol">:users</span>, <span class="hljs-symbol">:username</span>, <span class="hljs-symbol">unique:</span> <span class="hljs-literal">true</span>
</code></pre>
<p>Then you run the migration and that’s it. The database now ensures that no similar usernames are saved in the table.</p>
<p>For multiple associated columns, let’s assume we have a requests table with columns sender_id and receiver_id. Similarly, you simply create a migration and input the following code:</p>
<pre><code class="lang-ruby">add_index <span class="hljs-symbol">:requests</span>, [<span class="hljs-symbol">:sender_id</span>, <span class="hljs-symbol">:receiver_id</span>], <span class="hljs-symbol">unique:</span> <span class="hljs-literal">true</span>
</code></pre>
<p>And that’s it? <em>Uh oh, not so fast.</em></p>
<h3 id="heading-the-problem-with-the-multiple-column-migration-above">The problem with the multiple column migration above</h3>
<p>The problem is that the ids, in this case, are interchangeable. This means that if you have a sender_id of 1 and receiver_id of 2, the request table can still save a sender_id of 2 and receiver_id of 1, even though they already have a pending request.</p>
<p>This problem often happens in a self-referential association. This means both the sender and receiver are users and sender_id or receiver_id is referenced from the user_id. A user with user_id(sender_id) of 1 sends a request to a user with user_id(receiver_id) of 2.</p>
<p>If the receiver sends another request again, and we allow it to save in the database, then we have two similar requests from the same two users(sender and receiver || receiver and sender) in the request table.</p>
<p>This is illustrated in the image below:</p>
<p><img src="https://lh3.googleusercontent.com/9VNqmd8nuvhxKqJ3nVoZKS5ke1y5K-m6wQ7N5r8NPLSFYUnv3yeoMH2afGj89sGtsEhk3zsJbI30pB2WsgOOF1Xiijtqmv3mqbi1PxDzkIoQM0sfXGLZjcSTRrrIUTamG9RqGzEM" alt="Image" width="1258" height="686" loading="lazy"></p>
<h3 id="heading-the-common-fix">The common fix</h3>
<p>This problem is often fixed with the pseudo-code below:</p>
<pre><code class="lang-ruby"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">force_record_conflict</span></span>
    <span class="hljs-comment"># 1. Return if there is an already existing request from the sender to receiver </span>
    <span class="hljs-comment"># 2. If not then swap the sender and receiver</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>The problem with this solution is that the receiver_id and sender_id get swapped each time before saving to the database. Hence, the receiver_id column will have to save the sender_id and vice versa.</p>
<p>For example, if a user with sender_id of 1 sends a request to a user with receiver_id of 2, the request table will be as shown below:</p>
<p><img src="https://lh3.googleusercontent.com/FhGRXh1uZOdxMsL1CvfKsM82kazpp_smHl7LkxNHpoxCxX6sChTbve5lQAotyW0WsqEITf7Ddc3C2XYG2-wwppSW4glymJqgPu4JmbiU1uxXR52c7EvWft73UHGf5-1gfmNW4ziC" alt="Image" width="1258" height="686" loading="lazy"></p>
<p>This may not sound like an issue but it’s better if your columns are saving the exact data you want them to save. This has numerous advantages. For example, if you need to send a notification to the receiver through the receiver_id, then you’ll query the database for the exact id from the receiver_id column. This already became more confusing the moment you start switching the data saved in your request table.</p>
<h3 id="heading-the-proper-fix">The proper fix</h3>
<p>This problem can be entirely resolved by talking to the database directly. In this case, I’ll explain using PostgreSQL. When running the migration, you must ensure that the unique constraint checks for both (1,2) and (2,1) in the request table before saving.</p>
<p>You can do that by running a migration with the code below:</p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AddInterchangableUniqueIndexToRequests</span> &lt; ActiveRecord::Migration[5.2]</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">change</span></span>
        reversible <span class="hljs-keyword">do</span> <span class="hljs-params">|dir|</span>
            dir.up <span class="hljs-keyword">do</span>
                connection.execute(<span class="hljs-string">%q(
                    create unique index index_requests_on_interchangable_sender_id_and_receiver_id on requests(greatest(sender_id,receiver_id)</span>, least(sender_id,receiver_id));
                    create unique index index_requests_on_interchangable_receiver_id_and_sender_id on requests(least(sender_id,receiver_id), greatest(sender_id,receiver_id));
                ))
            <span class="hljs-keyword">end</span>

            dir.down <span class="hljs-keyword">do</span>
                connection.execute(<span class="hljs-string">%q(
                    drop index index_requests_on_interchangable_sender_id_and_receiver_id;
                    drop index index_requests_on_interchangable_receiver_id_and_sender_id;
                )</span>)
            <span class="hljs-keyword">end</span>    
        <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<h3 id="heading-code-explanation">Code explanation</h3>
<p>After creating the migration file, the reversible is to ensure that we can revert our database whenever we must. The <code>dir.up</code> is the code to run when we migrate our database and <code>dir.down</code> will run when we migrate down or revert our database.</p>
<p><code>connection.execute(%q(...))</code> is to tell rails that our code is PostgreSQL. This helps rails to run our code as PostgreSQL.</p>
<p>Since our “ids” are integers, before saving into the database, we check if the greatest and least (2 and 1) are already in the database using the code below:</p>
<pre><code class="lang-ruby">requests(greatest(sender_id,receiver_id), least(sender_id,receiver_id))
</code></pre>
<p>Then we also check if the least and greatest (1 and 2) are in the database using:</p>
<pre><code class="lang-ruby">requests(least(sender_id,receiver_id), greatest(sender_id,receiver_id))
</code></pre>
<p>The request table will then be exactly how we intend as shown in the image below:</p>
<p><img src="https://lh5.googleusercontent.com/LHiuQRNBeyui8vuXx1hMWZfzVOBBkccmnFUml2A4kehPHg1xcpC35LsRan_8oggdmYH0zvBardwpIXHWDA-hiFTH4Grd7D6tejAATSJZLpS0l1aLig00KD8NUx7yrtTmICD1C0tI" alt="Image" width="1258" height="686" loading="lazy"></p>
<p>And that’s it. Happy coding!</p>
<h3 id="heading-references">References:</h3>
<p><a target="_blank" href="https://edgeguides.rubyonrails.org/active_record_validations.html#uniqueness">Edgeguides</a> | <a target="_blank" href="https://thoughtbot.com/blog/the-perils-of-uniqueness-validations">Thoughtbot</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ A quick look at Rails Custom Validation ]]>
                </title>
                <description>
                    <![CDATA[ By Raymond Blessed I recently started working with Ruby (almost 2 months now) and Ruby on Rails (a little over 3 weeks). Working with Rails’ Active Record framework is one of my favorite things about Ruby on Rails. In this post, we will be looking at... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/a-quick-look-at-rails-custom-validation-9ab7e0f1af81/</link>
                <guid isPermaLink="false">66c3431a4f7405e6476b016a</guid>
                
                    <category>
                        <![CDATA[ coding ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 08 May 2019 16:33:30 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*otuQiVYDCBjZee9xZ0UnvA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Raymond Blessed</p>
<p>I recently started working with Ruby (almost 2 months now) and Ruby on Rails (a little over 3 weeks). Working with Rails’ Active Record framework is one of my favorite things about Ruby on Rails. In this post, we will be looking at validations in Active Record, custom ones particularly. Here is a quick intro to Active Record before we move to the good stuff.</p>
<p>Active Record is one of the core gems that make up Ruby on Rails. It is the part of the framework that deals with databases.</p>
<p>It is an ORM (Object Relational Mapping) framework that lets you build a schema for a database using pure ruby and it is based on the Active Record design pattern described by <a target="_blank" href="https://martinfowler.com/">Martin Fowler</a>. So, with Active Records, you are creating your DB, creating tables, storing, retrieving and deleting data using ruby which translates to SQL under the hood.</p>
<h3 id="heading-quick-intro">Quick Intro</h3>
<p>Suppose we have a student model with properties first name and last name. To use Active Record we just need to extend the <strong>ApplicationRecord</strong> and when we run <code>rails db:migrate</code> it gives us the SQL statement for it.</p>
<p>To interact with the database, we use methods inherited from the ApplicationRecord superclass.</p>
<p>It also supports associations and other database stuff.</p>
<p>For a detailed intro to Active Record, check out the official ruby on rails guide.</p>
<h3 id="heading-validation">Validation</h3>
<p>Because we write web applications for users other than ourselves, we cannot be sure that the users will always input valid data into the database. To enforce this, Active Record provides us a mini-validation framework that ensures the presence of data, uniqueness of certain fields, and so on.</p>
<p>Let’s look at our students table above. We wouldn’t want to create a user without a first name or last name which presently is possible. To mitigate this, we just need to modify our Student class like so:</p>
<p>With this modification, when you create a Student instance without the first name or last name attributes, it is an invalid student and active records will not persist it to the database.</p>
<p>Active record also provides us with methods to check if our data is valid or invalid:</p>
<p>With this, we do not even have to attempt to save the data.</p>
<p>Apart from just preventing the data from being persisted, Active Record also provides an error list that holds the attributes that failed validations and user-friendly messages to present to the users. These errors can be accessed as shown in the snippet below.</p>
<p>There is a lot more on validation but it’s not the topic of this article. For a deep dive, you can get an in-depth explanation from the ruby on rails guide chapter on Validation.</p>
<h3 id="heading-custom-validation">Custom Validation</h3>
<p>Sometimes, we might want to use certain validations that are more than just ensuring the presence of an attribute, length, uniqueness, or any of the helpers provided by Active Record. Luckily, Active Record allows us to define our own custom validations, which is the point of this article.</p>
<p>So, let’s say for our Student model, we have a compulsory student registration number column. It has to be filled from the registration form (I know this can be auto-generated) which should always start with the registration year. Now, Active Record does not provide this kind of validation out of the box, but has made it possible for us to define it and use it.</p>
<p>There are mainly two ways to define your own validation logic:</p>
<ul>
<li>Custom Validator</li>
<li>Custom Methods</li>
</ul>
<h4 id="heading-custom-validator"><strong>Custom Validator</strong></h4>
<p>To validate using a custom validator, you just need to define your validation logic in a class that extends <strong>ActiveModel::Validator</strong> and implements the validate method, which takes the record to be validated as its argument.</p>
<p>If validation fails, it adds the attribute to the errors array along with its error message. So, in our case, we’ll have RegNumValidator as seen below:</p>
<p>To use this validator in the Student model, we use the <code>validates_with</code> method:</p>
<p>With this, when a user tries to create a student with the wrong registration number, the record creation fails and an error message can be shown.</p>
<h4 id="heading-custom-methods"><strong>Custom Methods</strong></h4>
<p>To use custom methods for validation, you just need to define a method to use for validation in your model class and call it like you would call any of the in-built validations — using <code>validate</code>. Using the same logic as what we had above, our model would look like this:</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>I hope this article has given you the necessary knowledge to begin to explore Active Records validation and custom validation especially. Whenever you have a validation rule that is not part of the existing active record validation API, you can write one yourself.</p>
<p><a target="_blank" href="https://guides.rubyonrails.org/active_record_validations.html"><strong>Active Record Validations — Ruby on Rails Guides</strong></a><br><a target="_blank" href="https://guides.rubyonrails.org/active_record_validations.html">_Validations are used to ensure that only valid data is saved into your database. For example, it may be important to…_guides.rubyonrails.org</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <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>
        
            <item>
                <title>
                    <![CDATA[ Essential Gems for Rails Applications ]]>
                </title>
                <description>
                    <![CDATA[ By Clark Jason Ngo Gems are located in the Gemfile inside your project folder. Let’s have a look at some you’ll want to have. will_paginate Adds pagination to your app Installation Add to Gemfile gem 'will_paginate' Install bundle install Usage In a ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/cjn-essential-gems-for-rails-applications-75fed43d2798/</link>
                <guid isPermaLink="false">66d45e0547a8245f78752a14</guid>
                
                    <category>
                        <![CDATA[ Apps ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 07 Jan 2019 22:30:05 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*cw0oHjOoBMDeba6_.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Clark Jason Ngo</p>
<p>Gems are located in the Gemfile inside your project folder. Let’s have a look at some you’ll want to have.</p>
<h3 id="heading-willpaginate"><strong>will_paginate</strong></h3>
<p><strong>Adds pagination to your app</strong></p>
<h4 id="heading-installation"><strong>Installation</strong></h4>
<p>Add to <code>Gemfile</code></p>
<pre><code>gem <span class="hljs-string">'will_paginate'</span>
</code></pre><p>Install</p>
<pre><code>bundle install
</code></pre><p><strong>Usage</strong></p>
<p>In a .html.erb file, render page links in the view:</p>
<pre><code class="lang-erb"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">%=</span></span></span><span class="ruby"> will_paginate @places </span><span class="xml"><span class="hljs-tag">%&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">%</span></span></span><span class="ruby"> @places.each <span class="hljs-keyword">do</span> <span class="hljs-params">|place|</span> </span><span class="xml"><span class="hljs-tag">%&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">%=</span></span></span><span class="ruby"> place.name </span><span class="xml"><span class="hljs-tag">%&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">h1</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></span><span class="ruby"> <span class="hljs-keyword">end</span> </span><span class="xml"><span class="hljs-tag">%&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">%=</span></span></span><span class="ruby"> will_paginate @places </span><span class="xml"><span class="hljs-tag">%&gt;</span></span>
</code></pre>
<p>In your controller, you can define how many entries per page you want to display. In the example below, it will list 3 entries per page.</p>
<pre><code class="lang-ruby"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span></span>
  @places = Place.all.paginate(<span class="hljs-symbol">page:</span> params[<span class="hljs-symbol">:page</span>], <span class="hljs-symbol">per_page:</span> <span class="hljs-number">3</span>)
<span class="hljs-keyword">end</span>
</code></pre>
<p>Source: <a target="_blank" href="https://github.com/mislav/will_paginate">https://github.com/mislav/will_paginate</a></p>
<h3 id="heading-simpleform"><strong>simple_form</strong></h3>
<p><strong>Forms made easy!</strong></p>
<h4 id="heading-installation-1"><strong>Installation</strong></h4>
<p>Add to <code>Gemfile</code></p>
<pre><code>gem <span class="hljs-string">'simple_form'</span>
</code></pre><p>Install</p>
<pre><code>bundle install
</code></pre><p>Run the generator</p>
<pre><code>rails generate simple_form:install
</code></pre><p><strong>Usage</strong></p>
<p>In a <code>.html.erb</code> file:</p>
<pre><code class="lang-ruby">&lt;%= simple_form_for @place <span class="hljs-keyword">do</span> <span class="hljs-params">|f|</span> %&gt;
  &lt;%= f.input <span class="hljs-symbol">:name</span> %&gt;
  &lt;%= f.input <span class="hljs-symbol">:address</span> %&gt;
  &lt;%= f.input <span class="hljs-symbol">:description</span> %&gt;
  &lt;br /&gt;
  &lt;%= f.submit <span class="hljs-string">'Create'</span>, <span class="hljs-class"><span class="hljs-keyword">class</span>: '<span class="hljs-title">btn</span> <span class="hljs-title">btn</span>-<span class="hljs-title">primary</span>' %&gt;</span>
&lt;% <span class="hljs-keyword">end</span> %&gt;
</code></pre>
<p>Source: <a target="_blank" href="https://github.com/plataformatec/simple_form">https://github.com/plataformatec/simple_form</a></p>
<h3 id="heading-devise"><strong>devise</strong></h3>
<p><strong>Adds user management</strong></p>
<h4 id="heading-installation-2"><strong>Installation</strong></h4>
<p>Add to <code>Gemfile</code></p>
<pre><code class="lang-ruby">gem <span class="hljs-string">'devise'</span>
</code></pre>
<p>Install</p>
<pre><code class="lang-ruby">bundle install
</code></pre>
<p>Run the generator</p>
<pre><code class="lang-ruby">rails generate <span class="hljs-symbol">devise:</span>install
</code></pre>
<p>Configure device at <em>config/environments/development.rb</em></p>
<p>Add this line:</p>
<pre><code class="lang-ruby">config.action_mailer.default_url_options = { <span class="hljs-symbol">host:</span> <span class="hljs-string">'localhost'</span>, <span class="hljs-symbol">port:</span> <span class="hljs-number">3000</span> }
</code></pre>
<p>Edit code in <em>app/views/layouts/application.html.erb</em></p>
<p>Add this line:</p>
<pre><code class="lang-ruby">&lt;% <span class="hljs-keyword">if</span> notice %&gt;
  &lt;p <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">success</span>"&gt;&lt;%= <span class="hljs-title">notice</span> %&gt;&lt;/<span class="hljs-title">p</span>&gt;</span>
&lt;% <span class="hljs-keyword">end</span> %&gt;
&lt;% <span class="hljs-keyword">if</span> alert %&gt;
  &lt;p <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">alert</span> <span class="hljs-title">alert</span>-<span class="hljs-title">danger</span>"&gt;&lt;%= <span class="hljs-title">alert</span> %&gt;&lt;/<span class="hljs-title">p</span>&gt;</span>
&lt;% <span class="hljs-keyword">end</span> %&gt;
</code></pre>
<p>Add sign-up and login links in <em>app/views/layouts/application.html.erb</em></p>
<pre><code class="lang-ruby">&lt;p <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">navbar</span>-<span class="hljs-title">text</span> <span class="hljs-title">pull</span>-<span class="hljs-title">right</span>"&gt;</span>
&lt;% <span class="hljs-keyword">if</span> user_signed_in? %&gt;
  Logged <span class="hljs-keyword">in</span> as &lt;strong&gt;&lt;%= current_user.email %&gt;&lt;<span class="hljs-regexp">/strong&gt;.
  &lt;%= link_to 'Edit profile', edit_user_registration_path, :class =&gt; 'navbar-link' %&gt; |
  &lt;%= link_to "Logout", destroy_user_session_path, method: :delete, :class =&gt; 'navbar-link'  %&gt;
&lt;% else %&gt;
  &lt;%= link_to "Sign up", new_user_registration_path, :class =&gt; 'navbar-link'  %&gt; |
  &lt;%= link_to "Login", new_user_session_path, :class =&gt; 'navbar-link'  %&gt;
&lt;% end %&gt;
&lt;/p</span>&gt;
</code></pre>
<p>Force user to be redirected to login page if not logged in.</p>
<p>Edit in _app/controllers/application<em>controller.rb</em></p>
<pre><code class="lang-ruby">before_action <span class="hljs-symbol">:authenticate_user!</span>
</code></pre>
<p>Source: <a target="_blank" href="https://guides.railsgirls.com/devise">https://guides.railsgirls.com/devise</a></p>
<h3 id="heading-geocoder"><strong>geocoder</strong></h3>
<p><strong>Adds geocoding from Google API</strong></p>
<h4 id="heading-installation-3"><strong>Installation</strong></h4>
<p>Add to <code>Gemfile</code></p>
<pre><code class="lang-ruby">gem <span class="hljs-string">'geocoder'</span>
</code></pre>
<p>Install</p>
<pre><code>bundle install
</code></pre><p>Create a migration file, run this in your terminal:</p>
<pre><code>rails generate migration AddLatitudeAndLongitudeToModel latitude:float longitude:float
</code></pre><pre><code>rake db:migrate
</code></pre><p>Example of a migration file adding latitude and longitude columns for existing Places table:</p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AlterPlacesAddLatAndLng</span> &lt; ActiveRecord::Migration[5.0]</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">change</span></span>
    add_column <span class="hljs-symbol">:places</span>, <span class="hljs-symbol">:latitude</span>, <span class="hljs-symbol">:float</span>
    add_column <span class="hljs-symbol">:places</span>, <span class="hljs-symbol">:longitude</span>, <span class="hljs-symbol">:float</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>Add these lines in your <code>app/model/place.rb</code></p>
<pre><code class="lang-ruby">geocoded_by <span class="hljs-symbol">:address</span>
after_validation <span class="hljs-symbol">:geocode</span>
</code></pre>
<p>Add this script in <em><code>show.html.erb</code></em></p>
<pre><code class="lang-js">&lt;script&gt;
&lt;% <span class="hljs-keyword">if</span> @place.latitude.present? &amp;&amp; @place.longitude.present? %&gt;
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">initMap</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> myLatLng = {<span class="hljs-attr">lat</span>: &lt;%= @place.latitude %&gt;, lng: &lt;%= @place.longitude %&gt;};
  <span class="hljs-keyword">var</span> map = <span class="hljs-keyword">new</span> google.maps.Map(<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'map'</span>), {
    <span class="hljs-attr">zoom</span>: <span class="hljs-number">15</span>,
    <span class="hljs-attr">center</span>: myLatLng
  });
  <span class="hljs-keyword">var</span> marker = <span class="hljs-keyword">new</span> google.maps.Marker({
    <span class="hljs-attr">position</span>: myLatLng,
    <span class="hljs-attr">map</span>: map,
    <span class="hljs-attr">title</span>: <span class="hljs-string">'Hello World!'</span>
  });
}
&lt;/script&gt;
</code></pre>
<p>Source: <a target="_blank" href="https://www.rubydoc.info/gems/geocoder/1.3.7">https://www.rubydoc.info/gems/geocoder/1.3.7</a></p>
<h3 id="heading-figaro"><strong>figaro</strong></h3>
<p><strong>Easily configure your APIs in Heroku deployment</strong></p>
<h4 id="heading-installation-4"><strong>Installation</strong></h4>
<p>Add to <code>Gemfile</code></p>
<pre><code>gem <span class="hljs-string">'figaro'</span>
</code></pre><p>Install and create a commented <code>config/application.yml</code> file and add it to your <code>.gitignore</code></p>
<pre><code>bundle exec figaro install
</code></pre><p>Update your API keys in <code>config/application.yml</code></p>
<p>For updating API keys in heroku, go to your terminal:</p>
<pre><code>figaro heroku:set -e productionheroku restart
</code></pre><p>Source: <a target="_blank" href="https://github.com/laserlemon/figaro">https://github.com/laserlemon/figaro</a></p>
<h3 id="heading-carrierwave">carrierwave</h3>
<p><strong>image uploader</strong></p>
<h4 id="heading-installation-5"><strong>Installation</strong></h4>
<p>Add to <code>Gemfile</code></p>
<pre><code>gem <span class="hljs-string">'carrierwave'</span>
</code></pre><p>Install</p>
<pre><code>bundle install
</code></pre><p>In your terminal</p>
<pre><code>rails generate uploader Image
</code></pre><p>It will generate this:</p>
<pre><code>app/uploaders/image_uploader.rb
</code></pre><p>Create a migration file</p>
<pre><code>rails g migration add_image_to_courses image:string
</code></pre><p>Run the migration file</p>
<pre><code>rake db:migrate
</code></pre><p>In your model</p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> &lt; ApplicationRecord  <span class="hljs-title">mount_uploader</span> :<span class="hljs-title">image</span>, <span class="hljs-title">ImageUploaderend</span></span>
</code></pre>
<p>Add to a <code>html.erb</code> i.e. <code>app/views/instructor/courses/new.html.erb</code></p>
<pre><code class="lang-ruby">&lt;%= f.input <span class="hljs-symbol">:image</span> %&gt;
</code></pre>
<p>Add to controller <code>app/controllers/instructor/courses_controller.rb</code></p>
<pre><code class="lang-ruby">params.<span class="hljs-keyword">require</span>(<span class="hljs-symbol">:course</span>).permit(<span class="hljs-symbol">:title</span>, <span class="hljs-symbol">:description</span>, <span class="hljs-symbol">:cost</span>, <span class="hljs-symbol">:image</span>)
</code></pre>
<p>Add to <code>show.html.erb</code> i.e. <code>app/views/instructor/courses/show.html.erb</code></p>
<pre><code class="lang-ruby">&lt;%= image_tag @course.image, <span class="hljs-class"><span class="hljs-keyword">class</span>: '<span class="hljs-title">img</span>-<span class="hljs-title">fluid</span>' %&gt;</span>
</code></pre>
<p>Also update the following:</p>
<ul>
<li><code>app/views/courses/show.html.erb</code></li>
<li><code>app/views/courses/index.html.erb</code></li>
<li><code>app/views/instructor/courses/show.html.erb</code></li>
</ul>
<h4 id="heading-image-resolution-with-imagemagick-more-on-carrierwave"><strong>Image Resolution with ImageMagick, more on carrierwave</strong></h4>
<p>Carrierwave in shows that <code>MiniMagick</code> and <code>RMagick</code> can be used</p>
<p>It shows here <code>app/uploaders/image_uploader.rb</code></p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ImageUploader</span> &lt; CarrierWave::Uploader::<span class="hljs-title">Base</span></span>
  <span class="hljs-comment"># Include RMagick or MiniMagick support:</span>
  <span class="hljs-comment"># include CarrierWave::RMagick</span>
  <span class="hljs-comment"># include CarrierWave::MiniMagick</span>
</code></pre>
<h4 id="heading-installing-imagemagick"><strong>Installing ImageMagick</strong></h4>
<p>We need to update our development environment’s database of programs to make sure when we install a program we’re getting the latest version.</p>
<pre><code>$ sudo apt-get update
</code></pre><p>Install ImageMagick</p>
<pre><code>$ sudo apt-get install imagemagick
</code></pre><p>Installation MiniMagick</p>
<p>Add to <code>Gemfile</code></p>
<pre><code>gem <span class="hljs-string">'mini_magick'</span>
</code></pre><p>Install</p>
<pre><code>bundle install
</code></pre><p>Uncomment MiniMagick in <code>app/uploaders/image_uploader.rb</code></p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ImageUploader</span> &lt; CarrierWave::Uploader::<span class="hljs-title">Base</span></span>
  <span class="hljs-comment"># Include RMagick or MiniMagick support:</span>
  <span class="hljs-comment"># include CarrierWave::RMagick</span>
  <span class="hljs-keyword">include</span> CarrierWave::MiniMagick
</code></pre>
<p>That line gives CarrierWave the ability to reach out to the ImageMagick program we installed on our program, through the MiniMagick gem. This will allow us to resize the image.</p>
<p>Unlocks image-resizing abilities such as <code>resize_to_fill</code>, <code>resize_to_fit</code>, <code>resize_and_pad</code>, and <code>resize_to_limit</code>.</p>
<p>Add this in <code>app/uploaders/image_uploader.rb</code></p>
<pre><code class="lang-ruby"><span class="hljs-comment"># Process files as they are uploaded:</span>
process <span class="hljs-symbol">resize_to_fill:</span> [<span class="hljs-number">800</span>, <span class="hljs-number">350</span>]
</code></pre>
<h3 id="heading-integrating-amazon-s3-for-video-uploads">Integrating Amazon S3 for Video Uploads</h3>
<h4 id="heading-installation-6"><strong>Installation</strong></h4>
<p>Add this line to your application’s <code>Gemfile</code>:</p>
<pre><code>gem <span class="hljs-string">'carrierwave-aws'</span>
</code></pre><p>Run the bundle command from your shell to install it:</p>
<pre><code>bundle install
</code></pre><h4 id="heading-step-1-configuring-the-initializer">Step 1: Configuring the Initializer</h4>
<p>Normally we would install our gem first, however to prevent bugs when switching from fog to AWS we need to update our initializer first.</p>
<p>You can read the details of how to configure the carrierwave-aws gem <a target="_blank" href="https://github.com/sorentwo/carrierwave-aws#usage">in the Usage Section of the Documentation</a>. Following the pattern they specify, we should update <code>config/initializers/carrierwave.rb</code> to look like this:</p>
<pre><code class="lang-ruby"><span class="hljs-comment"># config/initializers/carrierwave.rb</span>
CarrierWave.configure <span class="hljs-keyword">do</span> <span class="hljs-params">|config|</span>
  config.storage    = <span class="hljs-symbol">:aws</span>
  config.aws_bucket = ENV[<span class="hljs-string">"AWS_BUCKET"</span>]
  config.aws_acl    = <span class="hljs-string">"public-read"</span>
  config.aws_credentials = {
      <span class="hljs-symbol">access_key_id:</span>     ENV[<span class="hljs-string">"AWS_ACCESS_KEY"</span>],
      <span class="hljs-symbol">secret_access_key:</span> ENV[<span class="hljs-string">"AWS_SECRET_KEY"</span>],
      <span class="hljs-symbol">region:</span>            ENV[<span class="hljs-string">"AWS_REGION"</span>]
  }
<span class="hljs-keyword">end</span>
</code></pre>
<p>Now save the file.</p>
<h4 id="heading-step-2-updating-our-gemfile">Step 2: Updating our Gemfile</h4>
<p>Add the <code>carrierwave-aws</code> gem as <a target="_blank" href="https://github.com/sorentwo/carrierwave-aws#installation">described by the documentation</a>. Edit the <code>Gemfile</code> to look like this:</p>
<pre><code>gem <span class="hljs-string">'carrierwave'</span>gem <span class="hljs-string">'mini_magick'</span>gem <span class="hljs-string">'carrierwave-aws'</span>
</code></pre><p>Save the file and run the command to install the gem.</p>
<pre><code>$ bundle install
</code></pre><p>Then restart your server.</p>
<h4 id="heading-step-3-add-region-to-applicationyml">Step 3: Add Region to application.yml</h4>
<p>We need to add a region to our <code>application.yml</code> file. Open up your <code>config/application.yml</code> and add this line to specify the region we want to use:</p>
<pre><code># config/application.yml
<span class="hljs-attr">AWS_ACCESS_KEY</span>: <span class="hljs-string">"Your-access-key"</span>
<span class="hljs-attr">AWS_SECRET_KEY</span>: <span class="hljs-string">"Your-secret-key"</span>
<span class="hljs-attr">AWS_BUCKET</span>:     <span class="hljs-string">"Your-bucket"</span>
<span class="hljs-attr">AWS_REGION</span>:     <span class="hljs-string">"us-east-1"</span>
</code></pre><p>Save the file.</p>
<h4 id="heading-step-4-updating-the-uploader">Step 4: Updating the Uploader</h4>
<p>If you remember from before, we specified inside the storage provider for the uploader to use <code>:fog</code>. Rather than that, we need to switch it to <code>:aws</code>.</p>
<pre><code class="lang-ruby"><span class="hljs-comment"># encoding: utf-8</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ImageUploader</span> &lt; CarrierWave::Uploader::<span class="hljs-title">Base</span></span>
  <span class="hljs-comment"># Include RMagick or MiniMagick support:</span>
  <span class="hljs-comment"># include CarrierWave::RMagick</span>
  <span class="hljs-keyword">include</span> CarrierWave::MiniMagick
  <span class="hljs-comment"># Choose what kind of storage to use for this uploader:</span>
  <span class="hljs-comment">#storage :file</span>
  storage <span class="hljs-symbol">:aws</span>
  <span class="hljs-comment"># A bunch more comments down here....</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>Save the file.</p>
<p>One more thing we will have to do is re-sync the localhost with heroku. To do this we need to run a simple command:</p>
<pre><code>$ figaro heroku:set -e production
</code></pre><p>Make sure uploads continue to work by uploading an image for a course and make sure it goes through successfully.</p>
<h3 id="heading-videojs"><strong>VideoJS</strong></h3>
<p>Add css file before <code>&lt;/head&gt;</code></p>
<pre><code class="lang-js">&lt;link href=<span class="hljs-string">"http://vjs.zencdn.net/5.12.6/video-js.css"</span> rel=<span class="hljs-string">"stylesheet"</span>&gt;
</code></pre>
<p>Add JavaScript files before <code>&lt;/body&gt;</code></p>
<pre><code>&lt;script src=<span class="hljs-string">"http://vjs.zencdn.net/5.12.6/video.js"</span>&gt;&lt;/script&gt;
</code></pre><pre><code class="lang-js">&lt;script src=<span class="hljs-string">"http://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"</span>&gt;&lt;/script&gt;
</code></pre>
<p>Note: You must place the videoJS <code>script</code> tags in the bottom of the body otherwise you will have issues loading the video player because of Turbolinks.</p>
<p>Thanks for reading! Hope this was helpful.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Why you should learn Ruby on Rails ]]>
                </title>
                <description>
                    <![CDATA[ By Błażej Kosmowski Every trend, technology, and even programming language has its peak in popularity that sooner or later will decrease slightly or by a considerable amount. If we lookup “state of ruby language” in Google we will most likely get man... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/why-ruby-on-rails-is-a-good-choice-in-2019-11abcc10f5a/</link>
                <guid isPermaLink="false">66c3671621ae2d74bb700a05</guid>
                
                    <category>
                        <![CDATA[ education ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ startup ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 11 Dec 2018 13:46:27 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*dMGwmevA6n8ebNsh8dGsag.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Błażej Kosmowski</p>
<p>Every trend, technology, and even programming language has its peak in popularity that sooner or later will decrease slightly or by a considerable amount. If we lookup “state of ruby language” in Google we will most likely get many results concerning Ruby’s alleged death and decrease in popularity. Still, I believe the truth is, Ruby is doing great and still remains a good technology to choose in 2019.</p>
<p>Here is why:</p>
<h4 id="heading-1-ruby-is-still-among-the-top-10-programming-languages">1. Ruby is still among the top 10 programming languages</h4>
<p>It is very unlikely that Ruby will die anytime soon as it is still featured among GitHub’s <a target="_blank" href="https://blog.github.com/2018-11-15-state-of-the-octoverse-top-programming-languages/">top programming languages of 2018</a>. What’s more? Large enterprises like <a target="_blank" href="https://stackshare.io/tnm/github">GitHub</a> and <a target="_blank" href="https://stackshare.io/airbnb/airbnb">Airbnb</a> are continuously using Ruby on Rails. Just a couple days ago, cloud computing giant AWS <a target="_blank" href="https://aws.amazon.com/about-aws/whats-new/2018/11/aws-lambda-supports-ruby/">added Ruby to its serverless computing solution — AWS Lambda</a> right next to Java, C#, Python and Node.js, which proves the stable position of the language.</p>
<p>Ruby may have slowed down (no pun intended) but it is far from dying, especially due to the vast amount of existing projects that have to be maintained and extended.</p>
<h4 id="heading-2-the-community-is-active-and-supportive">2. The community is active and supportive</h4>
<p>The Rails framework has over 3,500 contributors on <a target="_blank" href="https://github.com/rails/rails">GitHub</a>. Frequent updates and new gems created by developers ensure that the applications created using the framework can be developed more easily and delivered more quickly.</p>
<p>The active community regularly shares experiences and troubleshooting problems. With over 300,000 questions on <a target="_blank" href="https://stackoverflow.com/questions/tagged/ruby-on-rails?sort=newest&amp;pageSize=15">Stackoverflow</a> it is unlikely that you will have a really hard time finding a solution for a problem you are experiencing. Not only Ruby, but also Ruby on Rails has become mature over the years and its documentation has gotten very detailed and extensive — a great starting point for newcomers.</p>
<p>Ruby is not only Rails. More lightweight solutions like <a target="_blank" href="http://sinatrarb.com/">Sinatra</a>, frameworks offering different approaches like <a target="_blank" href="https://hanamirb.org/">Hanami</a>, and even frameworks for <a target="_blank" href="https://github.com/RailsEventStore">event sourcing</a> are growing in popularity and improving on what Ruby can offer.</p>
<h4 id="heading-3-ruby-constantly-evolves">3. Ruby constantly evolves</h4>
<p>With updates at least twice a year, Ruby creators make sure the language is not dying and constantly evolves. Despite the fact that the performance issues will not likely disappear any time soon due to some basic characteristics of Ruby (especially its dynamic nature), the release of Ruby 3 in 2020 is expected to introduce several improvements that can make Ruby <a target="_blank" href="https://planetruby.github.io/calendar/ruby3x3">significantly faster</a>.</p>
<h4 id="heading-4-its-really-great-for-startups-internal-tools-prototyping-and-whatnot">4. It’s really great for startups, internal tools, prototyping and whatnot</h4>
<p>Thanks to its intuitive, simple, and readable syntax resulting in much higher productivity, Ruby has been a great fit for startups or any company that would like to deliver (and extend) software products as soon as possible. Faster development means better savings (quicker time-to-market), which is important for startups with a limited budget. This way, more money can be invested in the development of additional stuff like updating features and marketing.</p>
<p>On the other hand, large-scale projects can benefit from Ruby on Rails using it as a prototyping tool or an efficient way to deliver proof-of-concept solutions. Because it is relatively easy and cheap to build and extend applications with Ruby, it is also a great option for building internal/back-end tools, where the performance is not a top priority.</p>
<p>It is not uncommon to use Ruby even for large, high-performance applications. This usually requires engineers that know how to craft high-performance applications in Ruby though, as speed is not inherently bundled with this language. Also, it might require some horizontal scaling.</p>
<h4 id="heading-5-ruby-has-a-well-established-code-style-recommendations">5. Ruby has a well-established code style recommendations</h4>
<p>Ruby is a mature programming language and stable technology, bringing more to the picture than simply being ‘trendy’. It is still possible to write bad code in Ruby, and some say it is fairly easy as the language is very flexible — it allows achieving the same result in multiple ways (not always the prettiest ones).</p>
<p>On the other hand, the language itself allows writing beautiful and readable code — this is encouraged by a well-established set of best practices related to implementation and testing. Such code, if written properly, can be easily understood and maintained by fellow developers, further improving on the stability and maintainability of the whole solution.</p>
<h4 id="heading-6-developer-happiness">6. Developer happiness</h4>
<p>A vast amount of libraries and resources for learning, a helpful and active community, well established best practices and beautiful, readable syntax — all this makes Ruby a programming language that is a pleasure to work with. It’s a language <a target="_blank" href="https://rubyonrails.org/doctrine/#optimize-for-programmer-happiness">oriented on developer happiness</a>.</p>
<p>In most cases, happy developers deliver better value to their customers. While there are other languages that try to mimic best aspects of Ruby (like Crystal), those are still immature technologies that need to prove themselves in production environments.</p>
<h4 id="heading-but-why-is-ruby-slowing-down">But why is Ruby slowing down?</h4>
<p>There is no easy answer to that question, but we can theorize about it. It is likely that Ruby has <a target="_blank" href="https://www.infoworld.com/article/3261566/application-development/ruby-finally-gains-in-popularity-but-go-plateaus.html">matured</a> enough and has started to lose some momentum. Lots of solutions, libraries and techniques were already created or designed so the need for new ones is not as significant as it once was. We can also see a slight decrease when it comes to appearance of new learning materials — most likely due to same reason.</p>
<p>Furthermore, the appearance of new languages and frameworks better suited for particular applications/solutions forced Ruby to share its part of the cake with the new players. Languages that are much less resource intensive, languages providing efficient libraries for specialized solutions related to ML/AI or other new concepts, and finally, languages designed around parallel processing — Ruby cannot compete with them in those areas, at least not yet. It is best to always use the right tool for the right job and Ruby is not one-size-fits-all kind of tool.</p>
<h4 id="heading-conclusions">Conclusions</h4>
<p>Even in 2019 Ruby remains a great choice for your development needs. There is no doubt that it is still a relevant language and it still attracts new followers and developers.</p>
<p>Last but not least, what should be kept in mind that there are no ‘bad’ programming languages in and of themselves, there are only badly chosen languages for particular use cases. So if you feel Ruby seems to be a great fit for you, do not hesitate, it is still out there among the top most popular technologies.</p>
<p><em>Originally published at</em> <a target="_blank" href="https://selleo.com/blog/why-ruby-on-rails-is-a-good-choice-in-2019"><em>selleo.com</em></a><em>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Beauty of Heroku Connect: Simplifying Database Synchronization ]]>
                </title>
                <description>
                    <![CDATA[ By Wilson Wang I’m currently a developer for Blueprint, an organization at UC Berkeley. We develop software pro bono for non-profits and advance technology for social good. This past year, my team worked on building a solution for The Dream Project. ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-beauty-of-heroku-connect-simplifying-database-synchronization-e57451d3b376/</link>
                <guid isPermaLink="false">66c360bec337fbd10a4b598a</guid>
                
                    <category>
                        <![CDATA[ Heroku ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Salesforce ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 12 Nov 2018 21:25:37 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*EPgspRCbfWjtUtUXoGnVHg.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Wilson Wang</p>
<p>I’m currently a developer for <a target="_blank" href="https://calblueprint.org/">Blueprint</a>, an organization at UC Berkeley. We develop software pro bono for non-profits and advance technology for social good. This past year, my team worked on building a solution for <a target="_blank" href="http://www.dominicandream.org/">The Dream Project.</a> The goal is to provide a better education for children in the Dominican Republic.</p>
<p>I am writing this post in hopes of sharing my experience of doing Salesforce integration using Heroku Connect for a Ruby on Rails/React Native app.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*EPgspRCbfWjtUtUXoGnVHg.png" alt="Image" width="800" height="239" loading="lazy"></p>
<h4 id="heading-what-is-heroku-connecthttpswwwherokucomconnect">What is <a target="_blank" href="https://www.heroku.com/connect">Heroku Connect</a>?</h4>
<blockquote>
<p>“Heroku Connect makes it easy for you to build Heroku apps that share data with your Salesforce deployment. Using bi-directional synchronization between Salesforce and Heroku Postgres, Heroku Connect unifies the data in your Postgres database with the contacts, accounts and other custom objects in the Salesforce database.”</p>
</blockquote>
<p>Another way to put it…</p>
<p>Heroku Connect assists with replacing your app’s Postgres database with a Salesforce database. Of course, since Rails apps connect natively to Postgres, you cannot do immediate calls and pushes to Salesforce without some API like the <a target="_blank" href="https://github.com/restforce/restforce">Restforce gem</a>.</p>
<p>In reality, the Postgres database that our Rails app will interact with serves as a disguise for Salesforce. It is a working middleman. All data must go through it before reaching Salesforce, and vice versa. Heroku Connect is the bridge that combines the capabilities of Force.com and Heroku without the need for a gem.</p>
<p>You might ask… why even bother learning Salesforce integration?</p>
<p>Well, Salesforce integration streamlines the process of storing and retrieving data. Especially customer data for businesses.</p>
<p>You can provide your customers with modernized computer systems for an improved user experience and workflow. You’ll be accelerating app development. It also creates better tools for informing management and sales on business performance.</p>
<p>This helps businesses achieve efficient levels of operation for business-to-consumer apps. It does this through instantaneous and accurate updates.</p>
<h4 id="heading-a-sample-project-for-inspiration">A Sample Project for Inspiration</h4>
<p>To give some background for the code snippets below in the tutorial, I will explain beforehand the project I was working on. This project got me introduced to Heroku Connect.</p>
<p>Previously, Dream recorded student information in a Salesforce database. This was not ideal for teachers to use. To make their lives easier, we created a user-friendly app. The app handled course creation, student enrollment, and attendance taking.</p>
<p>Due to the poor internet connection at Dream campuses, we turned to Heroku Connect for constant synchronization of updates. It synchronized updates on the Heroku Postgres database side and Salesforce database side.</p>
<p>All the code described in this demo is available in our <a target="_blank" href="https://github.com/calblueprint/dream-rails">project repo</a>. You can also check out the React side of the application <a target="_blank" href="https://github.com/calblueprint/dream-mobile">here</a>.</p>
<h3 id="heading-alright-lets-start-the-demo">Alright, let’s start the demo…</h3>
<h4 id="heading-overview">Overview</h4>
<p>I’m going to tackle this demo in the following order:</p>
<ol>
<li>Description of Tech</li>
<li>Setup (Heroku Postgres and Heroku Connect)</li>
<li>Heroku Connect Mappings + Notes</li>
<li>Changes to your local Rails app</li>
</ol>
<h4 id="heading-description-of-tech">Description of Tech</h4>
<ul>
<li>Force.com (<a target="_blank" href="https://developer.salesforce.com/">Salesforce Developer Account</a>)</li>
<li><a target="_blank" href="https://www.heroku.com/connect">Heroku Connect</a></li>
<li>Rails app (my Rails version was 5.1.4)</li>
</ul>
<h4 id="heading-setting-up-deploying-your-app-to-rails">Setting up: Deploying your app to Rails</h4>
<p>After setting up your Rails app, you want to deploy your app on Heroku. Here is a quick run-through on deploying your app:</p>
<ol>
<li>Login to your Heroku account, and you will be redirected to the dashboard on the top right. You will see a “New” button on a top right to create a new project. Type in your custom app name and create your app.</li>
<li>You will be redirected to the deploy page of your new app. Scroll down to the bottom to the section “Deploy using Heroku Git.” Follow the instructions on the page. (Note: after you add the Heroku Git remote you can alway update your Heroku app. You update by adding and commiting your changes and finally doing a git push <strong>heroku</strong> master.)</li>
</ol>
<p>Most likely, if this is your first time, you will face an error: “Heroku deployment failed because of sqlite3 gem error.” This is because Heroku uses Postgres instead of sqlite3. To fix this, check out this <a target="_blank" href="https://stackoverflow.com/questions/13083399/heroku-deployment-failed-because-of-sqlite3-gem-error.">Stack Overflow post</a>.</p>
<h4 id="heading-heroku-postgres">Heroku Postgres</h4>
<p>With your app deployed, your overview page should have the add-on Heroku Postgres. This is your usual database for deployed Heroku apps.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*R9kFu8MDX4RC17HJ" alt="Image" width="636" height="444" loading="lazy">
<em>Add-ons like Heroku Postgres or Heroku Connect appear in the Overview tab or Resources tab.</em></p>
<p>Click on this add-on to check the URL database info in the settings tab. Be sure to add your Postgres database URL to your Rails app.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*NOr58iU9H0g4xG_5" alt="Image" width="777" height="553" loading="lazy"></p>
<p>To add the database URL, you can either create an environment variable using the <a target="_blank" href="https://github.com/laserlemon/figaro">Figaro</a> gem:</p>
<p>or just include a URL variable in your database.yml file:</p>
<h4 id="heading-heroku-connect">Heroku Connect</h4>
<p>Next, click on configure add-ons or the resources tab, and search for Heroku Connect. Click provision to add the add-on.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*g85k6DdH9HyNB1vJ" alt="Image" width="800" height="497" loading="lazy"></p>
<p>You will then be redirected to the screen below. Note that the schema name is “salesforce” for now (feel free to change it as well), and you’re good to continue.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*WUvsdQ_IgEgV41S7Y9_hew.png" alt="Image" width="770" height="351" loading="lazy"></p>
<p>Click setup connection. Enter your Salesforce user info to establish the connection with the appropriate details.</p>
<p>You’re now done with the setup! Now we can move on to mappings.</p>
<h4 id="heading-mappings">Mappings</h4>
<p>I recorded a short video of creating a mapping for a Teacher object:</p>
<p>The video is a walkthrough for establishing mappings. There are a couple things I want to explain further that I personally got confused with. After reading these clarifications, I would recommend rewatching the video for a better understanding.</p>
<h4 id="heading-1-c">1. ‘__c’</h4>
<p>You may be asking why there are so many ‘__c’s that are appended at the end of my teacher object and teacher fields. Well, Salesforce actually appends this to each custom class/field.</p>
<p>So, tying back to my Rails project, the table name is now <em>Teacher__c</em> instead of Teacher and the columns/fields have changed from names like First_name, Last_name to _First<em>name__c</em>, _Last<em>name__c</em>. Some default fields like <em>sfid</em> or <em>createddate</em> are not custom, so they don’t require appending ‘__c’.</p>
<h4 id="heading-2-custom-fields">2. Custom Fields</h4>
<p>So, how do you create custom fields? Well, there’s actually a small arrow on the right side of your screen for you to edit objects and fields.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*BZ1PIjziwnyF2V3A" alt="Image" width="467" height="545" loading="lazy">
<em>Click on view object/fields to modify them respectively.</em></p>
<p>After each modification, remember to check if you also need to modify your Heroku Connect mappings.</p>
<h4 id="heading-3-two-way-syncing">3. Two Way Syncing</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*-CCzjvqWA4i5Aggx" alt="Image" width="800" height="391" loading="lazy"></p>
<p>I wanted to point out two very cool features about Heroku Connect’s Two-Way Syncing. The first is poll frequency, which regulates how often you want your Postgres database to update with Salesforce updates. Checking the Accelerate Polling box makes most operations pretty much instantaneous.</p>
<p>The second is the section on pushing data from your Postgres database to sync with the Salesforce database. You must check the box in order to have this feature work at all. However, right afterward, you will most likely see a warning pop up:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*AxFt3ybUi7xmipGk" alt="Image" width="800" height="235" loading="lazy">
<em>“Warning: Read-write mappings require a unique identifier to be specified.”</em></p>
<p>This is a layer of protection to ensure that you don’t accidentally create duplicate objects. It’s great if you have a unique identifier (in the video, each teacher has a unique email, so I made that my identifier). Otherwise, you can skip it and still have a functional Heroku Connect mapping. However, you may want to program your app to double check for existing records before creating an object.</p>
<h4 id="heading-changes-to-your-local-rails-app">Changes to your local Rails app</h4>
<p>Now that you have your Heroku Connect all nice and set up, it’s time for a quick local adjustment before you can interact with your Salesforce data.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*qqvmsH_-kzF_NeCh" alt="Image" width="734" height="280" loading="lazy"></p>
<p>In overview, you will see the name of your schema, in this case “salesforce”. If you had picked a different name during the provisioning phase, that name would show up here instead.</p>
<p>Because my Rails app’s table name is still Teacher, I need to change it to <em>Teacher__c</em> to correctly reference the Salesforce data. I must change the table name to the format _schema<em>name</em>._object<em>name</em> or <em>salesforce.teacher__c</em> to reflect the changes.</p>
<p>The other notable change applies if your model has validated statements, like my Teacher model. Following the validates keyword, we still have the old field names like first_name without ‘<strong>c’ and last_name without ‘</strong>c’. We need to change those names by either appending the ‘__c’ to the old field names or by creating separate methods:</p>
<p>Afterwards, create some objects in Salesforce and open up your Rails console to retrieve this info. (In the video, I called Teacher.all to display all Salesforce Teacher objects in my Rails console.) The information should also be reflected in the Heroku Connect explorer.</p>
<h3 id="heading-reflection">Reflection</h3>
<p>I spent a good half of my semester trying to figure out Salesforce integration. I did lots of research, experimented with different solutions, and plenty of support. In the end, it was a very enlightening experience to work with the cool features of Salesforce/Heroku/Rails. I also learned how much I’ve grown as a developer and reflect on my strengths and weaknesses.</p>
<p>Usually people implement the first solutions they find. They do this without understanding why it is good or bad. I researched and planned out three separate solutions before discovering Heroku Connect. Through this, I realized how important it was to weigh the pros and cons of different solutions before settling, even if more time is spent researching instead of implementing.</p>
<p>By using this knowledge, my team and I built an app to help teachers provide quality education for students in the Dominican Republic schools that have a poor connection to the Internet. We learned to persevere when times were hard because we knew that despite every long work session, every bug fix, every line of code, we had a mission, and every step of the way was another step towards improving the world.</p>
<p>This experience helped me to really prioritize the goal and the importance of doing quality work instead of immediately using the fastest way to go. Every solution is worth researching its pros and cons. It’s all about resilience and tenacity.</p>
<p>So to all developers out there, no matter what situation you’re in, don’t give up. Don’t be afraid of trying new solutions and failing. Stay positive and Happy Deving!</p>
<p><em>Wilson Wang is a junior at UC Berkeley studying computer science and data science. He is interested in developing software for improving business-customer relationships. Besides technology, Wilson is passionate about martial arts, architectural design, and landscape photography.</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*gcqfNtbXJmAFRUZiwkBHbw.jpeg" alt="Image" width="800" height="476" loading="lazy"></p>
<h4 id="heading-thanks-for-reading-to-learn-more-about-blueprint-follow-us-on-facebookhttpfacebookcomcalblueprint-and-instagramhttpswwwinstagramcomcalblueprint-and-visit-our-websitehttpscalblueprintorg">Thanks for reading! To learn more about Blueprint, follow us on <a target="_blank" href="http://facebook.com/CalBlueprint">Facebook</a> and <a target="_blank" href="https://www.instagram.com/calblueprint/">Instagram</a>, and visit our <a target="_blank" href="https://calblueprint.org/">website</a>!</h4>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
