<?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>Forem: Nathan Chung</title>
    <description>The latest articles on Forem by Nathan Chung (@hellonathanchung).</description>
    <link>https://forem.com/hellonathanchung</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%2F450996%2Ff8189c80-de3e-453b-95ea-04e39c1fedbf.jpeg</url>
      <title>Forem: Nathan Chung</title>
      <link>https://forem.com/hellonathanchung</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hellonathanchung"/>
    <language>en</language>
    <item>
      <title>How to query an API for your React Project!</title>
      <dc:creator>Nathan Chung</dc:creator>
      <pubDate>Fri, 09 Oct 2020 18:24:07 +0000</pubDate>
      <link>https://forem.com/hellonathanchung/how-to-query-an-api-for-your-react-project-2k1b</link>
      <guid>https://forem.com/hellonathanchung/how-to-query-an-api-for-your-react-project-2k1b</guid>
      <description>&lt;p&gt;&lt;strong&gt;This post requires previous knowledge/understanding of React and JS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For my capstone project, I noticed that there aren't many user forums giving access to Stock Market data. After spending some time going through stock market documentation, I now understand why.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an API?
&lt;/h2&gt;

&lt;p&gt;API stands for &lt;em&gt;Application Programming Interface&lt;/em&gt;. Many companies build API's for users to use and create their own awesome applications. In our case, we want to look into the stocks and a company like MarketStack for our project.&lt;/p&gt;

&lt;p&gt;First, we'll be using &lt;a href="//insomnia.rest"&gt;Insomnia&lt;/a&gt; to fetch market data and &lt;a href="https://marketstack.com/" rel="noopener noreferrer"&gt;MarketStack&lt;/a&gt; as our API. Luckily, most API's return JSON readable format which we'll make it easy for us to use!&lt;/p&gt;

&lt;p&gt;Insomnia allows you to test and query API's without needing to have everything built out. We'll be using Insomnia to test GET requests from MarketStack. Make sure to install &lt;em&gt;Insomnia Core&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;MarketStack provides free real-time and historical stock market data with thousands of tickers via REST API in JSON format, access to tons of exchanges, and you get 1000 queries a month. (10,000 for $10.00)&lt;/p&gt;

&lt;p&gt;Head on over to &lt;a href="https://marketstack.com/" rel="noopener noreferrer"&gt;https://marketstack.com/&lt;/a&gt; and click the following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FVrAIMIg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FVrAIMIg.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you're there, you'll be directed to sign up and register and you'll then have your own API key.&lt;/p&gt;

&lt;p&gt;Save it and write it down and make sure you don't expose it publicly.&lt;/p&gt;

&lt;p&gt;If you head over to MarketStack's documentation, there is a ton of data; end-of-day data, intraday data, stock exchanges, currencies, and everything you can think of... financially. &lt;/p&gt;

&lt;p&gt;The basic way you'll write a query for Apple like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://api.marketstack.com/v1/eod?access_key=YOURAPIKEY&amp;amp;symbols=AAPL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Insomnia
&lt;/h2&gt;

&lt;p&gt;Now let's take that to Insomnia.&lt;/p&gt;

&lt;p&gt;In this program, you have a bunch of ways to test API's, send data to your own backend, and more! For our example, we'll send a fetch request to get information on Apple.&lt;/p&gt;

&lt;p&gt;Take the same query from above and paste it into Insomnia. Make sure your options are set to 'GET'. You'll receive a 200 OK message along with all your stock data!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F22MV3Rr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F22MV3Rr.png" alt="stocks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our data, let's see an example of its usage within a React project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hiding your API key
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a .env file within your React at the highest level.
This is important because in most cases, API keys are private and for you/your group. Exposing your API key could literally be very costly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fcw2ErHk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fcw2ErHk.png" alt=".env"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;then in &lt;code&gt;.gitignore&lt;/code&gt; be sure to add .env to prevent uploading to Github!&lt;/p&gt;

&lt;p&gt;Now in your &lt;code&gt;.env&lt;/code&gt;, set your API key by starting off with&lt;br&gt;
&lt;code&gt;REACT_APP_MARKETSTACK_API_KEY='YOUR_API_KEY'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Replace the single quotes with your own API key. Make sure to include REACT_APP, otherwise it won't work.&lt;/p&gt;

&lt;p&gt;run &lt;code&gt;npm start&lt;/code&gt; to spin up your server and let's check if everything worked correctly.&lt;/p&gt;
&lt;h2&gt;
  
  
  Testing Fetch Requests
&lt;/h2&gt;

&lt;p&gt;Now to ensure that it's working, go to a component and type the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;    &lt;span class="nf"&gt;componentDidMount&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="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REACT_APP_MARKETSTACK_API_KEY&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;If all things went correctly, you should see your API key now showing in the console.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now the API key is hidden we can fetch certain data. Within your React application, we can run fetch. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In one of my components, I'm going to run a fetch request.&lt;/p&gt;

&lt;p&gt;We'll break it down into a few parts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REACT_APP_MARKETSTACK_API_KEY&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;stockTicker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MSFT&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;URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`http://api.marketstack.com/v1/eod access_key=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_KEY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;symbols=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;stockTicker&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Let me explain what we did. We set the variable &lt;code&gt;API_KEY&lt;/code&gt; to our API Key stored in our .env file. We call it with &lt;code&gt;process.env&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We set &lt;code&gt;stockTicker&lt;/code&gt; to &lt;code&gt;MSFT&lt;/code&gt; for now so that we can include it within our &lt;code&gt;URL&lt;/code&gt;, taking our API and providing the previous variables within the link.&lt;/p&gt;

&lt;p&gt;This way, we're avoiding hardcoding data, except for the stockTicker which we'll implement later, and reducing the lines of code.&lt;/p&gt;

&lt;p&gt;Now, let's run our fetch request.&lt;/p&gt;

&lt;p&gt;Most fetch requests are done in this format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch('http://example.com/stocks.json')
  .then(response =&amp;gt; response.json())
  .then(data =&amp;gt; console.log(data));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we're fetching JSON data from an API and sending it to the console. The data is not instantly set, but instead, we're returned a promise containing the response. We extract that JSON content but using &lt;code&gt;.json()&lt;/code&gt; on the response and then can handle that data in different ways such as setting it to state or running console.log. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Data&lt;/code&gt; can be anything but make sure that the variable names are consistent. For example, &lt;code&gt;data&lt;/code&gt; can be &lt;code&gt;stockData&lt;/code&gt; if that helps writing cleaner code. Especially, if you're working with multiple fetch requests.&lt;/p&gt;

&lt;p&gt;If you have your own backend&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;    &lt;span class="nf"&gt;componentDidMount&lt;/span&gt;&lt;span class="p"&gt;()&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="nf"&gt;fetchStock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;fetchStock&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;API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REACT_APP_MARKETSTACK_API_KEY&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;stockTicker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MSFT&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;URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`http://api.marketstack.com/v1/eod access_key=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_KEY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;symbols=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;stockTicker&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&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;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;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="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What you should get in return is a series of Stock data by day.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FzcXuA1P.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FzcXuA1P.png" alt="fetch data"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There you have it! The next things you could do is map the X axis by day and the Y axis by highs and lows for that day.&lt;/p&gt;

&lt;p&gt;:)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to use Geocoder</title>
      <dc:creator>Nathan Chung</dc:creator>
      <pubDate>Tue, 08 Sep 2020 20:45:33 +0000</pubDate>
      <link>https://forem.com/hellonathanchung/how-to-use-geocoder-302a</link>
      <guid>https://forem.com/hellonathanchung/how-to-use-geocoder-302a</guid>
      <description>&lt;p&gt;You're working on your Rails project and you've saved all the addresses. Great!&lt;br&gt;
What do you do now? If you're using the Google API and need to generate markers, you'll need latitude and longitude coordinates.&lt;/p&gt;

&lt;p&gt;Geocoder is an amazing gem that takes an address and finds its latitude/longitude coordinates! It can also do it the opposite way as well. Saving the info in the backend can also reduce the API requests you've done in total.&lt;/p&gt;

&lt;p&gt;How do you install it?&lt;/p&gt;

&lt;p&gt;First, my original model looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Activity&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:user_activities&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;through: :user_activities&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:comments&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

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



&lt;p&gt;Now, we want to do two things:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem install geocoder&lt;/code&gt; &lt;/p&gt;

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

&lt;p&gt;We've now installed the gemfile and can start using the geocoder.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g migration AddLatitudeAndLongitudeToModel latitude:float longitude:float&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It will create a migration file within your db/migrate folder&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;db:migrate&lt;/code&gt; and make sure it migrates successfully!&lt;/p&gt;

&lt;p&gt;Now we're going to make a few additions to our &lt;code&gt;Activity&lt;/code&gt; Model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Activity&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;geocoded_by&lt;/span&gt; &lt;span class="ss"&gt;:complete_address&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;complete_address&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;zipcode&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;compact&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;', '&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;has_many&lt;/span&gt; &lt;span class="ss"&gt;:user_activities&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;through: :user_activities&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:comments&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

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



&lt;p&gt;We've added &lt;code&gt;geocoded_by :complete_address&lt;/code&gt; and also have defined what the &lt;code&gt;complete_address&lt;/code&gt; is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;complete_address&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;zipcode&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;compact&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;', '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To verify if this is working, we can call &lt;br&gt;
&lt;code&gt;Activity.first.complete_address&lt;/code&gt; and if everything worked successfully, you'll be returned your new, complete address. This takes the data from the model and creates a full address.&lt;/p&gt;

&lt;p&gt;From here we can call something like this:&lt;br&gt;
&lt;code&gt;Activity.last.geocode&lt;/code&gt;&lt;br&gt;
and it will query geocode along with an API and return the coordinates.&lt;/p&gt;

&lt;p&gt;Now, to limit requests we make every time our activities are queried we can do an &lt;code&gt;after_validation&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Activity&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;geocoded_by&lt;/span&gt; &lt;span class="ss"&gt;:complete_address&lt;/span&gt;
  &lt;span class="n"&gt;after_validation&lt;/span&gt; &lt;span class="ss"&gt;:geocode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;if: &lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;address&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;present?&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;address_changed?&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;complete_address&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;zipcode&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;compact&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;', '&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;has_many&lt;/span&gt; &lt;span class="ss"&gt;:user_activities&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;through: :user_activities&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:comments&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

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



&lt;p&gt;There you go. I hope you &lt;em&gt;find&lt;/em&gt; what you're looking for. ;)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Task Lister Lite</title>
      <dc:creator>Nathan Chung</dc:creator>
      <pubDate>Wed, 26 Aug 2020 04:51:17 +0000</pubDate>
      <link>https://forem.com/hellonathanchung/understanding-task-lister-lite-37cl</link>
      <guid>https://forem.com/hellonathanchung/understanding-task-lister-lite-37cl</guid>
      <description>&lt;p&gt;I said I'd cover MVC in my next few posts. Today, I am a liar.&lt;/p&gt;

&lt;p&gt;I started mod-3 of Flatiron this week and Task Lister gave me some trouble. It's our first week of javascript and I'm hoping this blog will help break things down.&lt;/p&gt;

&lt;p&gt;Let's start off with the HTML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;title&amp;gt;Flatiron Task Lister&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="./style.css" /&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="main-content"&amp;gt;
      &amp;lt;h1&amp;gt;Task Lister Lite™️&amp;lt;/h1&amp;gt;

      &amp;lt;form id="create-task-form" action="#" method="post"&amp;gt;
        &amp;lt;label for="new-task-description"&amp;gt;Task description:&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="text"
          id="new-task-description"
          name="new-task-description"
          placeholder="description"
        /&amp;gt;
        &amp;lt;input type="submit" value="Create New Task" /&amp;gt;
      &amp;lt;/form&amp;gt;

      &amp;lt;div id="list"&amp;gt;
        &amp;lt;h2&amp;gt;My Todos&amp;lt;/h2&amp;gt;
        &amp;lt;ul id="tasks"&amp;gt;&amp;lt;/ul&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;script src="./src/index.js" defer&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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



&lt;p&gt;The main point of this lab is to allow you to to create tasks and them to the list.&lt;/p&gt;

&lt;p&gt;To start off, we'll need to load the HTML before the javascript text.&lt;/p&gt;

&lt;p&gt;You can do this in a few ways:&lt;/p&gt;

&lt;h1&gt;
  
  
  defer
&lt;/h1&gt;

&lt;p&gt;in your index.html you can add &lt;code&gt;defer&lt;/code&gt; to the script section so it will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.html
&amp;lt;script src="./src/index.js" defer&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  DOMContentLoaded
&lt;/h1&gt;

&lt;p&gt;in your /src/index.js file, it should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.js
document.addEventListener("DOMContentLoaded", () =&amp;gt; {
  // your code here
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;or moving the script to the very bottom of the body. That will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.html
//a bunch of previous code
    &amp;lt;/div&amp;gt;
    &amp;lt;script src="./src/index.js" &amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Long story short, you'll learn to choose one or the other and run with it. You need to load the HTML before you can run the script and these methods allow the HTML file to fully load before the JS begins.&lt;/p&gt;

&lt;p&gt;You can open the index.html file in your browser with an extension called &lt;code&gt;Live Server&lt;/code&gt;. &lt;br&gt;
Now, once that's done, here's what it should look like. (Colors may vary).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z8x7KgK8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/JsMTOdh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z8x7KgK8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/JsMTOdh.png" alt="task lister"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you click around, you'll notice nothing works! This is where the javascript comes in.&lt;/p&gt;
&lt;h2&gt;
  
  
  Let's get it
&lt;/h2&gt;

&lt;p&gt;To start off, we need to create a constant that's identifying the form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.html
      &amp;lt;form id="create-task-form" action="#" method="post"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can gain access to this by doing a document.querySelector("#create-task-form");&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.js
const taskForm = document.querySelector("#create-task-form");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Why are we doing this?
&lt;/h2&gt;

&lt;p&gt;The main deliverable is that a user should be able to add a task-based off of their description and then press submit. Then, it should populate below.&lt;/p&gt;

&lt;p&gt;Now we have the &lt;code&gt;taskForm&lt;/code&gt; variable. We'll need another a few more. We want to take the data from the taskForm and add them this section in the html.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.html
      &amp;lt;div id="list"&amp;gt;
        &amp;lt;h2&amp;gt;My Todos&amp;lt;/h2&amp;gt;
        &amp;lt;ul id="tasks"&amp;gt;&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can do this by using another document.querySelector. It'll look like this:&lt;br&gt;
&lt;code&gt;const taskList = document.querySelector("#tasks");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Wonderful!&lt;/p&gt;

&lt;p&gt;Typically with form data, when you press submit a &lt;code&gt;post&lt;/code&gt; request will be made. Its &lt;em&gt;default&lt;/em&gt; behavior is something we're going to prevent. How?&lt;/p&gt;

&lt;p&gt;Through this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.js
taskForm.addEventListener("submit", function (event) {
  event.preventDefault();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This stops what would usually happen when you press submit!&lt;/p&gt;

&lt;p&gt;So, great. We've stopped the regular behavior but now what do we want to do with the form data we received? We can take a look at what's being passed through the form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.html
&amp;lt;form id="create-task-form" action="#" method="post"&amp;gt;
        &amp;lt;label for="new-task-description"&amp;gt;Task description:&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="text"
          id="new-task-description"
          name="new-task-description"
          placeholder="description"
        /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is the section that responds to where we're filling in the data on the website. This input field actually has a &lt;code&gt;value&lt;/code&gt; once we press submit. We can access that by doing the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.js
  const newTask = document.querySelector("#new-task-description").value;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This sets newTask to be the &lt;strong&gt;value&lt;/strong&gt; of the new-task-description field.&lt;/p&gt;

&lt;p&gt;So now that we have the value of whatever task we typed in, we need to add that to our &lt;code&gt;taskList.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.js
TaskForm.addEventListener("submit", function (event) {
  event.preventDefault();
  const newTask = document.querySelector("#new-task-description").value;

## NEW CODE ##
  taskList.innerHTML += `&amp;lt;li&amp;gt; ${newTask}
  &amp;lt;/li&amp;gt;`;

});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We take the *&lt;em&gt;value&lt;/em&gt; from &lt;code&gt;#new-task-description&lt;/code&gt; and add that to &lt;code&gt;taskList.innerHTML&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Type a new task into your browser and it will look something like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--onsvr0rI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/NoI8y3t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--onsvr0rI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/NoI8y3t.png" alt="new tasks added"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You were able to create a new task! Note, once you press submit, the created task is still in the form field. We can delete that by adding the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.js

const taskForm = document.querySelector("#create-task-form");

const taskList = document.querySelector("#tasks");

taskForm.addEventListener("submit", function (e) {
  e.preventDefault();
  const newTask = document.querySelector("#new-task-description").value;

  taskList.innerHTML += `&amp;lt;li&amp;gt; ${newTask}
  &amp;lt;/li&amp;gt;`;
###NEW CODE###
  // taskForm.reset();
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This takes the taskForm and resets it each time a task is submitted.&lt;/p&gt;

&lt;p&gt;Finally, we're going to create delete button. How would we do this? Simple!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.js

taskForm.addEventListener("submit", function (e) {
  e.preventDefault();
  const newTask = document.querySelector("#new-task-description").value;

  taskList.innerHTML += `&amp;lt;li&amp;gt; ${newTask}
###NEW CODE###
  &amp;lt;button data-action = "delete"&amp;gt; X &amp;lt;/button&amp;gt;
  &amp;lt;/li&amp;gt;`;
##############
  taskForm.reset();
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With each addition of a task, we add a button with the label "X". This could be anything you'd like. We now have a button but if you press it, nothing will happen. We need to create one more function that will "listen" for a click.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#index.js
taskList.addEventListener("click", function (e) {
  if (e.target.dataset.action === "delete") {
    e.target.parentElement.remove();
  }
});

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



&lt;p&gt;We create another Event Listener that's waiting for a user to click on the x. Once we do that, we're making sure that if the action, delete, of the function matches with &lt;code&gt;&amp;lt;button data-action&amp;gt;&lt;/code&gt; we remove the &lt;strong&gt;parent element&lt;/strong&gt; of the button which will be the full list item.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z5zn27Pw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/NWMrcma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z5zn27Pw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/NWMrcma.png" alt="li"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Without the parentElement specified, you will only be able to delete the button and not the full task.&lt;/p&gt;

&lt;p&gt;Try it out!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>flatiron</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Grabbing Coffee with MVC</title>
      <dc:creator>Nathan Chung</dc:creator>
      <pubDate>Wed, 12 Aug 2020 20:26:53 +0000</pubDate>
      <link>https://forem.com/hellonathanchung/grabbing-coffee-with-mvc-3hpc</link>
      <guid>https://forem.com/hellonathanchung/grabbing-coffee-with-mvc-3hpc</guid>
      <description>&lt;p&gt;This is the first post of a RAILS series directed at Flatiron students.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Congratulations!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You've just finished mod 1. Well done.&lt;/p&gt;

&lt;p&gt;You've crushed enumerables into your brain, built your first CLI app, and now you're being introduced to a totally new topic called Rails. Woah.&lt;/p&gt;

&lt;p&gt;First, let me say this. It's going to be stressful and it might feel overwhelming but we'll get through this. For now, let's take a deep breath.&lt;/p&gt;

&lt;p&gt;I'll give you a moment.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;inhale&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;exhale&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ruby on Rails is a wonderful and "magical" framework that allows developers, like you, to rapidly build massive applications. For example, Github &amp;amp; Airbnb both use Rails in their stack.&lt;br&gt;
Here’s a &lt;a href="https://www.netguru.com/blog/what-is-ruby-on-rails-used-for"&gt;link to 34 companies using rails&lt;/a&gt;. Just like how active records simplifies some methods for us, Rails does as well. Today, I'll be teaching you one aspect of it: MVC.&lt;/p&gt;

&lt;h1&gt;
  
  
  Model, View, and Controller Architecture
&lt;/h1&gt;

&lt;p&gt;Model, View, and Controller, MVC, is a way to have a &lt;em&gt;separation of concerns&lt;/em&gt; amongst components. &lt;/p&gt;

&lt;p&gt;What does this mean?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Separation of Concerns is achieved by encapsulating information inside a section of code that has a well-defined interface. It is easiest to think of in terms of modularity."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is a great way to say the &lt;strong&gt;model&lt;/strong&gt;, &lt;strong&gt;view&lt;/strong&gt;, and &lt;strong&gt;controller&lt;/strong&gt; deal with their own problems and methods. Model problems deal with model problems, view problems deal with view problems, and controller problems deal with? You guessed it. Controller problems.&lt;/p&gt;

&lt;p&gt;You're dividing the work of an application into three separate systems. Why is this good? It allows developers to easily identify problems, test methods, and scales as your application grows.&lt;/p&gt;

&lt;h3&gt;
  
  
  Model
&lt;/h3&gt;

&lt;p&gt;The model component deals with data-related logic. It handles the relationship between the data and databases, validations, and associations between models.&lt;/p&gt;

&lt;p&gt;Think about when we kept our data in our methods class. Now we keep data in our db and our class methods in a model.&lt;/p&gt;

&lt;p&gt;Note, how would you get that all the way a user? Most would and should not need to know about all that information in the backend.&lt;/p&gt;

&lt;p&gt;In our example, we'll call the model a barista.&lt;/p&gt;

&lt;h3&gt;
  
  
  View
&lt;/h3&gt;

&lt;p&gt;The View presents the model’s data to the user. The user can see the data and the pretty layouts but when they want to modify layout or content, they're actually using a controller that communicates to the model.&lt;/p&gt;

&lt;p&gt;The view is the counter where you see the menu and order your goods.&lt;/p&gt;

&lt;h3&gt;
  
  
  Controller
&lt;/h3&gt;

&lt;p&gt;The controller is a link between your views and your model. In Rails, the controller handle requests from the users and communicates to the model-based off on the type of request made.&lt;/p&gt;

&lt;p&gt;This will be the cashier!&lt;/p&gt;

&lt;h3&gt;
  
  
  Putting it all together.
&lt;/h3&gt;

&lt;p&gt;Let's take an example of you entering a coffee shop.&lt;br&gt;
You, self.name, enter a coffee shop and walk up to the counter(view) to order your coffee. You browse the menu at the counter (view) through a list of things you can order. You can view desserts, sandwiches, and coffee.&lt;/p&gt;

&lt;p&gt;The cashier greets you with a warm welcome.&lt;/p&gt;

&lt;p&gt;"Hello, I'm Nate, your &lt;strong&gt;controller&lt;/strong&gt; what can I do for you?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;drip? Nah.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Ooo, do I want a pour-over? Had that yesterday&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Hm... I know.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;"One americano, please.&lt;/p&gt;

&lt;p&gt;Nate, the cashier/controller, receives your request and yells "AMERICANO" to the barista(model) in the back. He just told the model what to do and then smiles back at you asking "anything else?"&lt;/p&gt;

&lt;p&gt;&lt;em&gt;no, I'm good.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You, AND the cashier, don't need to know that that a good espresso needs 9 bars of pressure, 30 pounds of pressure on a 51mm diameter tamper, and should hit a ratio of 36ml to 25seconds for a proper extraction.&lt;/p&gt;

&lt;p&gt;The barista(model) alone holds all that coffee-related knowledge.&lt;/p&gt;

&lt;p&gt;The cashier(controller) is simply routing your request that you made at the counter(view) to the barista(model).&lt;/p&gt;

&lt;p&gt;You, as the end-user, just want good tasting coffee to push you through another lab.&lt;/p&gt;

&lt;p&gt;How does the barista(model) know what to make? By the cashier (controller)!&lt;/p&gt;

&lt;p&gt;Now, the barista(model) has just finished your coffee. Are you going to go behind the counter and grab the coffee?&lt;/p&gt;

&lt;p&gt;You can...but you'll probably also be banned from the shop.&lt;/p&gt;

&lt;p&gt;Nate, the controller, will grab that americano and hand it back to you at the counter.&lt;/p&gt;

&lt;p&gt;Voila! You've just experienced an MVC framework.&lt;/p&gt;

&lt;p&gt;You made a request for an americano to the cashier(controller). The cashier just routed the specific request to the barista(model) who used their deep knowledge of coffee-brewing to make you a specific kind of coffee. They could have made you any type of coffee.&lt;/p&gt;

&lt;p&gt;Affogatos, cappuccinos, macchiatos, and just about anything else! However, because they were given specific instructions by the cashier, the barista(model) made the americano that you &lt;strong&gt;requested.&lt;/strong&gt;&lt;br&gt;
After creating the americano, they hand it to the cashier/controller and they hand it to you back at the counter.&lt;/p&gt;

&lt;p&gt;Here’s a quick diagram to wrap up what happens!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ROqgPBG9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dm2jy79t9cx6irrjansh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ROqgPBG9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dm2jy79t9cx6irrjansh.png" alt="ordering a coffeet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There could have been plenty of errors here.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The barista may not have known how to make an americano. That'd be a problem with the model.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The cashier may have had no idea how to process your credit card. That'd be a problem with the controller.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You may have asked for something that's not on the menu. That'd be a problem with you. (no offense)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With the MVC framework, problems and solutions are easy to identify.&lt;/p&gt;

&lt;h6&gt;
  
  
  I'll continue discussing MVC and increase the specificity over the next few blog posts! Comment below any questions and concerns you may have.
&lt;/h6&gt;

&lt;p&gt;Icons made by &lt;a href="https://www.flaticon.com/authors/ultimatearm" title="ultimatearm"&gt;ultimatearm&lt;/a&gt; from &lt;a href="https://www.flaticon.com/" title="Flaticon"&gt; &lt;/a&gt;&lt;a href="http://www.flaticon.com"&gt;www.flaticon.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flatiron</category>
      <category>bootcamp</category>
      <category>ruby</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Awesome title</title>
      <dc:creator>Nathan Chung</dc:creator>
      <pubDate>Wed, 12 Aug 2020 00:15:18 +0000</pubDate>
      <link>https://forem.com/hellonathanchung/awesome-title-4omh</link>
      <guid>https://forem.com/hellonathanchung/awesome-title-4omh</guid>
      <description>&lt;p&gt;This is my awesome content.&lt;/p&gt;

</description>
      <category>awesometag1</category>
      <category>awesometag2</category>
      <category>awesometag3</category>
    </item>
  </channel>
</rss>
