<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daniel Wilder</title>
    <description>The latest articles on DEV Community by Daniel Wilder (@dauncy).</description>
    <link>https://dev.to/dauncy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F270514%2Fc779f2a3-28f0-4328-bf2c-1aac26a82d0c.jpeg</url>
      <title>DEV Community: Daniel Wilder</title>
      <link>https://dev.to/dauncy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dauncy"/>
    <language>en</language>
    <item>
      <title>Rails API, beyond the basics</title>
      <dc:creator>Daniel Wilder</dc:creator>
      <pubDate>Wed, 19 Feb 2020 20:18:26 +0000</pubDate>
      <link>https://dev.to/dauncy/rails-api-beyond-the-basics-hdm</link>
      <guid>https://dev.to/dauncy/rails-api-beyond-the-basics-hdm</guid>
      <description>&lt;p&gt;For my final project at Flatiron, I developed a web app for volunteers to signup and help keep the streets of San Francisco clean. The idea was inspired by my roommate. She expressed frustration in the way San Francisco Public Works operates. There was even one time where she contacted public works multiple times, contacted our district supervisor, and contacted the mayor as well. It took all of that just to deal with the issue outside of our building. After dealing with this, She came up with the idea to leverage community to address some of San Francisco's issues. And so, I built "SF Heroes," a React web application to do just that. &lt;/p&gt;

&lt;p&gt;While the front end design took a while to build, it is actually the backend that I am most proud of. During this project I leveraged the power of a Rails API and the API is doing all of the heavy lifting. In previous projects I used a Rails backend as well. However, for those projects the API was built to do less lifting and I relied on the logic of the front end. This may have worked for previous projects, but not SF Heroes. &lt;/p&gt;

&lt;p&gt;SF Heroes has a map page which displays the SF 311 Public Works cases I gathered. Users are given the ability to sort through these cases by status, district, and/or service subtype. Users can apply as many filters as they's like. On my initial draft I had originally made a fetch request to get all of the 311 cases. Each filter would be set in state. On submission, the display map would be set by filtering through all of the cases using state. However, this method created many bugs on the display map. &lt;/p&gt;

&lt;p&gt;On my first draft, my backend controller looked something like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CommunityEventController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
     &lt;span class="n"&gt;community_events&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;CommunityEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;
     &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="n"&gt;community_events&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt; 

&lt;span class="k"&gt;end&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see I am calling on the ActiveRecord relations method "all" to return all instances of the cases. However, given the bugs I was dealing with, I decided to remove some logic from the front end and leverage the power of the back end.&lt;/p&gt;

&lt;p&gt;Upon revision, I decided to use the ActiveRecord relations method "where" instead. &lt;br&gt;
Let's take a look at the revision...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CommunityEventController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;

           &lt;span class="n"&gt;community_events&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
           &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:district&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                &lt;span class="n"&gt;community_events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CommunityEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;title: 
                &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;district: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:district&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;status: 
                &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;


           &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:district&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                    &lt;span class="n"&gt;community_events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CommunityEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;district: 
                    &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:district&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;title: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;


           &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:district&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                        &lt;span class="n"&gt;community_events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CommunityEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;status: 
                        &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;district: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:district&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;

           &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                    &lt;span class="n"&gt;community_events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CommunityEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;status: 
                     &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;title: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;

           &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:district&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                    &lt;span class="n"&gt;community_events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CommunityEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;district: 
                    &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:district&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; 

           &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                    &lt;span class="n"&gt;community_events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CommunityEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;title: 
                    &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;

           &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                    &lt;span class="n"&gt;community_events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CommunityEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;status: 
                    &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:status&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;
           &lt;span class="k"&gt;else&lt;/span&gt; 
                    &lt;span class="n"&gt;community_events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CommunityEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="k"&gt;end&lt;/span&gt; 
                    &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="n"&gt;community_events&lt;/span&gt;


    &lt;span class="k"&gt;end&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ActiveRecord relations method "where" takes in two arguments the key of the query params and the value of the query params. It then uses SQL to query the database for all of the instances that match those parameters. My fetch request on the front end was now pinging the database for instances that matched only the query parameters set by the user. &lt;/p&gt;

&lt;p&gt;The front end code looked something like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:3000/community-events?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;filterData&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;district&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;`district=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;district&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
             &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="s2"&gt;`title[]=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;`&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;`status[]=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;`&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Accept&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jwt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 

            &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SET_DISPLAY_MAP&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;displayMap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every filter applied updates the fetch URL accordingly.&lt;/p&gt;

&lt;p&gt;Using the relations method "where" gave me one other positive outcome. I was now able to pass in an array of values for one key. Users could now select multiple values to chain on to their fetch URL. &lt;/p&gt;

&lt;p&gt;One thing to note: &lt;br&gt;
If you want rails to understand one param having multiple values, you need to use an array in the URL. Let's say I want all of the cases where the tittle of those cases is either "Graffiti" or "Noise Reports," I would need to pass those query params as such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:3000/community-events?title[]=Graffiti&amp;amp;title[]=Noise%20Report 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After leveraging the power of my backend and ActiveRecord relations, my display map had less bugs and rendered content faster.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>api</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Object Oriented JavaScript</title>
      <dc:creator>Daniel Wilder</dc:creator>
      <pubDate>Wed, 22 Jan 2020 20:04:56 +0000</pubDate>
      <link>https://dev.to/dauncy/object-oriented-javascript-3hc7</link>
      <guid>https://dev.to/dauncy/object-oriented-javascript-3hc7</guid>
      <description>&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When creating dynamic web apps, JavaScript is an amazing tool which enables us to write functions that can be used to manipulate the DOM and handle client-server interactions. However, as our web apps grow in size, these functions can quickly get meshed together in a complicated web, leaving more room for bugs and code which is generally harder to read and change. It's very likely that as our web apps grow in size we will be dealing with dozens, if not hundreds of HTML elements. In turn, our DOM manipulation will quickly become messy. Luckily for us, there is a way to structure our code in a way that changes the layout from a web of free-standing functions to a structure or collection of components or cells. This way of organizing our code is known as Object Oriented Programming.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object Oriented Programmin: An Overview:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In object oriented programming, our code is separated into containers. These containers are composed pf data, information, variables as well as behaviors we define pertaining to the information. Object oriented programming gives us structure. It establishes the relationship between our data and the functions that define the behavior. We structure our code in a way where we instantiate data that inherits behavioral properties we define in the class the object is associated with. Benefits of organizing our code in such a way include: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Our code becomes easier to change. There is a clear place to add/remove code.&lt;/li&gt;
&lt;li&gt;We can design our code in a way that the behavioral functions we define only interact with the data they are supposed to. &lt;/li&gt;
&lt;li&gt;Our code is easier to replicate. When an object is created with unique data, the instance methods we define in the class operate in such a way that is unique to that object.&lt;/li&gt;
&lt;li&gt;Our code becomes easier to read by adding more organization.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In Practice&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On a high level, this makes sense. Let's take a look at how object oriented JavaScript differs from purely functional JavaScript. Here is some functional javascript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Honda Civic&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mileage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;goVroom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;typeOfCar&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; goes vrooooom!!`&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;howOldIsMyCar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`my car has &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; miles.`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;driveToSanDiego&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;mileage&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;goVroom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; Honda Civic goes vrooooom!!&lt;/span&gt;

&lt;span class="nf"&gt;howOldIsMyCar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; my car has 50000 miles.&lt;/span&gt;

&lt;span class="nx"&gt;mileage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;driveToSanDiego&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;howOldIsMyCar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; my car has 51000 miles.&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code works and we can tell it is related to behaviors and attributes of a car. However, there is nothing that structurally relates this code.&lt;br&gt;
If we were to write the previous code in an object oriented way, it would encode the relationship of the data and behavioral methods. That code would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;goVroom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`{this.model} goes vrooooom!!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;howOldIsMyCar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`My car has &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; miles.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;driveToSanDiego&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mileage&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;jalopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;astro&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;150000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;jalopy&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; Car {model: "astro", mileage:150000};&lt;/span&gt;

&lt;span class="nx"&gt;jalopy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goVroom&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; astro goes vrooooom!!&lt;/span&gt;

&lt;span class="nx"&gt;jalopy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;howOldIsMyCar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; My car has 150000 miles.&lt;/span&gt;

&lt;span class="nx"&gt;jalopy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;driveToSanDiego&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nx"&gt;jalopy&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; Car {model: "astro", mileage:160000};&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the Car object is a class or the structure for all of JavaScript object oriented programming. We create an instance of this class, in this case it's jalopy. This takes in two arguments: model and mileage.The instance methods we defined have access to the data using the keyword &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt;. This refers to the instance or specific object associated with the class. Our code now has structure and methods associated for specific instances of data. Neat!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Object oriented programming is a powerful way to organize our code and allow specific instances of related data to share behavioral functions. We have gone over how it is not only good practice to keep this when working with our models and the backend but with the frontend as well, using the class object constructor provided to us by JavaScript.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Transitioning from SQLite to Postgres in Rails</title>
      <dc:creator>Daniel Wilder</dc:creator>
      <pubDate>Thu, 02 Jan 2020 21:07:46 +0000</pubDate>
      <link>https://dev.to/dauncy/transitioning-from-sqlite-to-postgres-in-rails-56on</link>
      <guid>https://dev.to/dauncy/transitioning-from-sqlite-to-postgres-in-rails-56on</guid>
      <description>&lt;p&gt;After spending some time creating a single page web application with a rails API and a vanilla JavaScript frontend, I decided I wanted to host the application on cloud platform such as &lt;a href="https://www.heroku.com/" rel="noopener noreferrer"&gt;Heroku&lt;/a&gt;. A cloud-based platform is a great way to host applications and make it easy for friends and potential employers to see what you have been working on. An important thing to keep in mind before hosting your rails app is what database are you working with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sqlite Vs. Postgres&lt;/strong&gt;&lt;br&gt;
The default rails database is operated through sqlite. sqlite is great for the novice developer because it can be run in local memory and stored in small files in your local working directory that are easily created and moved. Given how sqlite stores its files on disks, it is not intended to be used for production. On the Heroku website it explains that Heroku's stack is an ephemeral filesystem. You can do all the CRUD actions with this filesystem, but it clears its contents periodically. Meaning, if you were to use a sqlite database, the entire database would be deleted at least once every 24 hours. If you'd like to read more about how Heroku's filesystem is managed, you can click &lt;a href="https://devcenter.heroku.com/articles/sqlite3" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Given the nature of the filesystem stack, Heroku recommends using the Postgres database. &lt;br&gt;
Postgres is different than sqlite in how it stores files. Postgres databases are only portable once they are hosted on a server. Practically, this means that any changes you make to your database will not be persistent until the database is hosted on a server. This is a very useful feature during the development phase of your project. If you are working with one or more partners on your project and are using a host like github during development, you will likely run into merge conflicts with the database if you are using a locally stored database like sqlite. Because of this, Postgres is a better database system to use for applications intended for production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How To Use Postgres With Rails&lt;/strong&gt;&lt;br&gt;
If you don't already have Postgres installed, you can download it &lt;a href="https://www.postgresql.org/download/macosx/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you have Homebrew installed on your computer you can also use your computer's terminal to install postgres by typing the following command into the command line:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;brew install postgresql&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Once you have postgres installed, you can create a new rails app. &lt;br&gt;
Rails has a built-in function to set the application's default database. &lt;br&gt;
simply run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;rails&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="n"&gt;postgresql&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you'd like, you can also set the name of the database and its associated username and password. &lt;br&gt;
Before creating your new rails app&lt;br&gt;
type the following commands into the command line.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;su -postgres&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;&lt;code&gt;create role &amp;lt;appName&amp;gt; with &amp;lt;createdb&amp;gt; login password &amp;lt;password1&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;replace the words in &amp;lt;&amp;gt; with the names you'd like to fill in. &lt;br&gt;
Afterwards, you can create your new rails app with the command listed above. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Change an existing sqlite database to postgres&lt;/strong&gt;&lt;br&gt;
Up until now, we have only discussed how to create a new rails app with a postgres database. However, if you want to transition from sqlite to postgres mid-development, you can follow these steps:&lt;/p&gt;

&lt;p&gt;In your gemfile you will want to change the line&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'sqlite'&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'pg'&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then run&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bundle install&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;After you will want to access your config/database.yml file.&lt;br&gt;
change the lines from&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;development:
  adapter: &lt;/span&gt;&lt;span class="n"&gt;sqlite3&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;development&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqlite3&lt;/span&gt;
  &lt;span class="ss"&gt;pool: &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="ss"&gt;timeout: &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;

&lt;span class="ss"&gt;test:
  adapter: &lt;/span&gt;&lt;span class="n"&gt;sqlite3&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqlite3&lt;/span&gt;
  &lt;span class="ss"&gt;pool: &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="ss"&gt;timeout: &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;

&lt;span class="ss"&gt;production:
  adapter: &lt;/span&gt;&lt;span class="n"&gt;sqlite3&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;production&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqlite3&lt;/span&gt;
  &lt;span class="ss"&gt;pool: &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="ss"&gt;timeout: &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;development:
  adapter: &lt;/span&gt;&lt;span class="n"&gt;postgresql&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;my_database_development&lt;/span&gt;
  &lt;span class="ss"&gt;pool: &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="ss"&gt;timeout: &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;
&lt;span class="ss"&gt;test:
  adapter: &lt;/span&gt;&lt;span class="n"&gt;postgresql&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;my_database_test&lt;/span&gt;
  &lt;span class="ss"&gt;pool: &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="ss"&gt;timeout: &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;

&lt;span class="ss"&gt;production:
  adapter: &lt;/span&gt;&lt;span class="n"&gt;postgresql&lt;/span&gt;
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="n"&gt;my_database_production&lt;/span&gt;
  &lt;span class="ss"&gt;pool: &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="ss"&gt;timeout: &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next run&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails db:create &amp;amp;&amp;amp; rails db:migrate&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;And your app will now be using postgres as the database. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hosting on Heroku&lt;/strong&gt;&lt;br&gt;
Once you are ready to host your finished application on Heroku, you can follow these steps:&lt;/p&gt;

&lt;p&gt;You will need to login to your existing Heroku account, or you can create one &lt;a href="https://signup.heroku.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;br&gt;
run the command&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;heroku login&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;this will prompt you for your info.&lt;/p&gt;

&lt;p&gt;After log in, run the command&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;heroku create&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;and a new Heroku app with a random name will be created.&lt;/p&gt;

&lt;p&gt;If you would like to rename the application you can run&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;heroku apps:rename appName&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;run&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;to add all the changes and&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git commit -m "commit message"&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;to commit the changes. &lt;/p&gt;

&lt;p&gt;Lastly run&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git push heroku master&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;and you are done!&lt;/p&gt;

</description>
      <category>rails</category>
      <category>postgres</category>
    </item>
    <item>
      <title>The Command Line</title>
      <dc:creator>Daniel Wilder</dc:creator>
      <pubDate>Wed, 04 Dec 2019 20:50:34 +0000</pubDate>
      <link>https://dev.to/dauncy/the-command-line-2f2d</link>
      <guid>https://dev.to/dauncy/the-command-line-2f2d</guid>
      <description>&lt;p&gt;The Command line is a powerful tool and one you should become familiar with. Today most people use what is called a Graphical User Interface (GUI) to interact with their computer. A GUI is a way to communicate with a computer using icons and the "point-and-click" method. However, many software developers rely on the command line to perform tasks because it can increase efficiency and allow you to perform tasks not available through GUIs. In this post I will briefly touch up on what the command line is, how to access it, and display some time-saving shortcuts...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A Brief History Of the Command Line&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
During the 60's and 70's when computers were growing in popularity and functionality, many users would interact with one main computer, known as a mainframe, using a terminal.  A terminal primarily consisted of a monitor and keyboard. Each user would use a remote terminal to communicate with the mainframe to perform tasks. Simply put, a computer terminal was a way for a user to interact with a computer to enter, display, and/or print data.&lt;/p&gt;

&lt;p&gt;Nowadays, we emulate the terminal using a "terminal emulator" like Terminal in OSX. We no longer communicate with a remote computer but rather with the computer we are operating on. &lt;br&gt;
Because we are operating on computers that are the complete package, when we start a terminal session, we are also initializing a shell program. What you see on the screen will be the shell program. &lt;/p&gt;

&lt;p&gt;Because we are operating with the complete package, Your computer's terminal and shell program work together. Your terminal handles the input going in and displays the output to the shell. The software that handles the input and uses the computer's central processing unit to interpret input and render output is called the shell. If you are using a Mac, your default shell will most like be bash. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Using a Terminal Emulator&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Now that we've discussed briefly the history of the terminal and how it works, let's discuss some commonly used commands and some less common but nifty shortcuts. &lt;/p&gt;

&lt;p&gt;To launch a terminal session type "terminal" in your computer's finder or search spotlight (cmd space). &lt;/p&gt;

&lt;p&gt;Once you are in the shell, here are some helpful commands to help you get started:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pwd&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Print Working Directory: this command does exactly what it sounds like it does. Prints your Working Directory. It tells your terminal to display what directory/folder you are currently in.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ls&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;List: This command lists all of the files in your current directory.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd  and cd ~&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Change Directory: These both will change your working directory to your home or root directory. You can also type a specific directory in which you would like to change your working directory to.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd ..&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This moves your working directory one directory up from your current working directory.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Make Directory: This command creates a new directory or folder.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;touch&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This command creates a new file in your current working directory&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl a&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Takes you back to the beginning of the line you are typing on.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl e&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Takes you to the end of of the line you are typing on.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl l&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Clears the screen.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl c&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Terminates whatever you are running. &lt;/p&gt;

&lt;p&gt;These are just a few commands to get started with and some others that are useful to know. If you would like a more extensive list of commands &lt;a href="https://github.com/0nn0/terminal-mac-cheatsheet" rel="noopener noreferrer"&gt;Here is one&lt;/a&gt; that provides a lot of useful commands to know. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Ruby and Bang(s)</title>
      <dc:creator>Daniel Wilder</dc:creator>
      <pubDate>Wed, 13 Nov 2019 20:48:21 +0000</pubDate>
      <link>https://dev.to/dauncy/ruby-and-bang-s-5gop</link>
      <guid>https://dev.to/dauncy/ruby-and-bang-s-5gop</guid>
      <description>&lt;p&gt;Chances are during your course of learning ruby, you will come across some exclamation marks in your ruby code. Most people know this as a plain ol' "exclamation mark" (!). And they are happy with that. But not us Rubyists! we call these little guys bangs. If you are like me when you first saw this operator, you may have been a little intimidated by its implications and implementations. However, studying the documentation and practicing the functionality can help us understand the use of bangs. In this post I will discuss pairing bang methods with other built-in ruby methods and what that means for your code. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a bang?&lt;/strong&gt;&lt;br&gt;
When paired with other built-in ruby methods, the bang operator will change the original object the method is called on in place of creating a new object. &lt;br&gt;
For example let's say we have an array of numbers and we only wanted to see the the unique numbers in that array. Luckily for us, ruby has a built in method called .uniq.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uniq&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we then call the original array object, ruby will output just that. The original unaltered array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;array&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we pair the .uniq method with the bang operator, we seemingly accomplish the same thing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uniq!&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, when we call on the original array object, something different happens. We no longer have access to all of the original elements particularly those we excluded with the .uniq method. This is due to the functionality of the bang operator. Remember, the bang operator works with ruby's methods to alter the existing object- not create a new object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;array&lt;/span&gt; 
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, this seems, great! We can clean up our code and cut out many lines of code without having to assign new variables to new objects created by our built in methods. If only that were the case. The bang operator has another functionality. When called, it coerces our data into boolean expressions and inverts the truth value of that data. &lt;br&gt;
For example...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's take another look at our array. It's not unlikely that at a later point we would want to call on our array object. However, if we were to forget that we had previously called the .uniq! method, and we used that method again...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uniq!&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we would no longer get our array of unique elements. Instead we would receive a nil value. This is due to the bang operators boolean inversion functionality. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The bang operator has its use in ruby and in a later article I will discuss more practical applications of the bang operator. like != or not equals to and the double bang (!!) operator. However, it is important to understand what a bang does and how it modifies methods first. Because the bang operator is destructive by nature, use caution when pairing it with other methods&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
