<?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: wenglin1</title>
    <description>The latest articles on Forem by wenglin1 (@wenglin1).</description>
    <link>https://forem.com/wenglin1</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%2F329719%2F3d9d7cc5-38e7-4335-8ac5-c8c41ccac5f4.png</url>
      <title>Forem: wenglin1</title>
      <link>https://forem.com/wenglin1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/wenglin1"/>
    <language>en</language>
    <item>
      <title>Simple Shopping Cart with JS/JSON</title>
      <dc:creator>wenglin1</dc:creator>
      <pubDate>Thu, 12 Mar 2020 21:56:39 +0000</pubDate>
      <link>https://forem.com/wenglin1/simple-shopping-cart-with-js-json-jdp</link>
      <guid>https://forem.com/wenglin1/simple-shopping-cart-with-js-json-jdp</guid>
      <description>&lt;p&gt;With JavaScript is an object-oriented programming language for front-end developers. With JavaScript you are able to manipulate what the front page of your website displays and the different interactive elements to enhance user-experience. These elements includes, clicking, hovering, submitting, searching, etc. &lt;/p&gt;

&lt;p&gt;To start off, I already have a Rails backend setup, with three models: products, cart_items, cart. This is my ruby seed data transformed into JSON:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl9kb8jp6ov3sxb7q2rqv.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl9kb8jp6ov3sxb7q2rqv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we setup our frontend, first create an index.html file. Depending on what code editor you are using, there will be a pre-established html:5 function which you can type in and it will generate a simple html setup:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr2qt1mlygeyh5dd5z30a.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr2qt1mlygeyh5dd5z30a.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After we create our JavaScript file where we will put most of our code in, index.js. Remember to add it to our index.html file with a script tag. Remember to put defer in front, which will tell the index.html file to run our index.js last so that it can read and display what our code is trying to output: &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6u8tp2458tot7e4qy9qn.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6u8tp2458tot7e4qy9qn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, I also added a couple "div" tags, which will be where our information displays. "clothes-box" is where we will show all our clothes. "SideNav" is where we will display our shopping cart, with the list of items, and all the way at the bottom of the sideNav we have another "div" where we will display the price and checkout button. &lt;/p&gt;

&lt;p&gt;Now that we have our HTML setup, we can start writing our code for JS. From here on out, all the code will be in our index.js file. First we have to fetch our JSON data with: &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fygkdhqyhnbg0sgcwnwes.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fygkdhqyhnbg0sgcwnwes.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
These line of codes fetches the data from our API and transform the response into readable JSON, and then transforms it into an array of objects that can then be called on by another function to display each data to our liking. Don't worry about RenderAllProducts, it will be a function we will be creating next: &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi6nkts8dpv677u0jqohp.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi6nkts8dpv677u0jqohp.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
RenderAllProducts we're calling on an array with forEach to display each product with another function RenderOneProduct inside:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpbte8ozo5fjmkwijcnw1.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpbte8ozo5fjmkwijcnw1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
In our RenderOneProduct function first find the "clothes-box div" to display all our products and set it to a variable with document.querySelector. Next create a new div element and set it to a variable. Next using the JS method innerhtml, we will write out html code for how our products will be displayed. Our product card will have the image, name, price, and "add to cart" button. Remember to add the id of the button so that we can target it later. Then we add it to our "clothes-box" by using the append method.&lt;br&gt;
Our products will display like this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8gxtkgaey6g0r1wxh0p4.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8gxtkgaey6g0r1wxh0p4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we have to render all the products we have in our cart by fetching our data again: &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fff7x9ag3vr5uepulgyw2.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fff7x9ag3vr5uepulgyw2.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F77sas9v6l7yyxox9kgdc.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F77sas9v6l7yyxox9kgdc.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7k98dg3ravctpvqt60a3.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7k98dg3ravctpvqt60a3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
This time, we will only want the price and name of the product with a "delete" button.&lt;br&gt;
It will display like so:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhg7sk9e995j4x4d2k4ms.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhg7sk9e995j4x4d2k4ms.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that everything is rendering like we want we can start making our buttons work with the method "addEventListener". First we start with our "add to cart" button. Inside our renderOneProduct function, we will write our event listener:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjnppivgis7yk38jqjfht.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjnppivgis7yk38jqjfht.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkzftp1w8z47eysdza7tm.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkzftp1w8z47eysdza7tm.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Let walkthrough what we did. First find the element for our button, good thing we gave it an ID earlier, so that we can set it to a variable. Next we add a "click" event listener which will give a response every time we click the button. Set a variable for the "list-of-items" to our global scope, so we can call on it later. We then set "list-of-items" to empty string so that our cart-items dont repeat themselves when we add them to the shopping cart. To save it in our backend so that it doesnt dissapear when we refresh the page, we need to create another fetch with the method "POST". "POST" creates a new cart_item, with the attributes of cart.id and product.id, then we send it to JSON and JSOn will respond by appending it to our renderALlCartItems. It will work like this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpukfkxqolcrxyr8a8aan.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpukfkxqolcrxyr8a8aan.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we create our eventListener for "remove" button in our RenderAllCartItem function. This will delete the product from our cart: &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh9m94pxixoc8qluvkvdc.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh9m94pxixoc8qluvkvdc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Lets walkthrough the code. First set variable for the "remove" button, next create our event listener "click". The (.remove()) method deletes the selected element, which is our newLi. In order to save it to the backend we need to create another fetch, this time with the method "DELTE", and then with the response we sent to JSON and receive from JSON we push it to renderAllCartItem. It should work like this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyoc3dix2zu42kc35un05.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyoc3dix2zu42kc35un05.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally we will write the code for our checkout div. Like what we did for everything else, first set the variable for our "checkout" div. Then we create a new div element:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhdwhgp71bgsgpghfxnls.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhdwhgp71bgsgpghfxnls.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Our checkout will have subtotal, tax (the subtotal * our set tax rate), total (the subototal + tax), and a checkout button. The different variables are the equations that will add up the price and show up in our checkout. Then we append it to our checkout variable. It should look like this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4az1fe2qehrdawzchqb6.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4az1fe2qehrdawzchqb6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Now we create our event listener for the checkout button: &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm19q1veqr9shbjzwxv6b.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm19q1veqr9shbjzwxv6b.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
When we set click the checkout button, there will be an alert box, everything will go back to $0 and the cart will return an empty array.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwnqzct28l5ijv7xiwu47.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwnqzct28l5ijv7xiwu47.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to add some CSS to it to make it look alot more appealing you can visit this blog and learn how to: &lt;a href="https://dev.to/iqramqra/5-basic-design-concepts-for-front-end-devs-19am"&gt;https://dev.to/iqramqra/5-basic-design-concepts-for-front-end-devs-19am&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you follow everything and add some css to it, it will look like this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnl2n2doe2f68u6ranrt1.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnl2n2doe2f68u6ranrt1.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how you create a simple shopping cart using JavaScript and Rails API.&lt;/p&gt;

&lt;p&gt;If you are still confused you can visit the following site for more information.&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch&lt;/a&gt;&lt;br&gt;
&lt;a href="https://htmlcheatsheet.com/js/" rel="noopener noreferrer"&gt;https://htmlcheatsheet.com/js/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>events</category>
      <category>json</category>
    </item>
    <item>
      <title>RUBY BASICS</title>
      <dc:creator>wenglin1</dc:creator>
      <pubDate>Thu, 20 Feb 2020 05:01:07 +0000</pubDate>
      <link>https://forem.com/wenglin1/ruby-basics-50i7</link>
      <guid>https://forem.com/wenglin1/ruby-basics-50i7</guid>
      <description>&lt;p&gt;Hello there, if you are like me, fresh out of college with a useless degree that will get you nowhere and are interested in trying something new, like coding. Then RUBY is the language for you. It is simple, and easy to understand. &lt;/p&gt;

&lt;p&gt;Ruby was designed and developed in the mid 1990s by Yukihiro "Matz" Matsumoto. Yukihiro designed Ruby so that it will be easy to read and applicable by humans. Other programming languages focus are designed to make our machines run efficiently and more effective. According to Yukihiro, "They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves."&lt;/p&gt;

&lt;p&gt;Let's start off with the basics. Like other programming languages Ruby has 6 data types: Strings, Numbers, Booleans, Symbols, Arrays, and Hashes. In order to find out what data type something is, you add &lt;em&gt;.class&lt;/em&gt; to the end of the data.&lt;/p&gt;

&lt;p&gt;1)&lt;strong&gt;Strings&lt;/strong&gt;: A string is any combination of letter or number that is wrapped in single or double quotation marks. You can convert into a string using &lt;em&gt;.to_s&lt;/em&gt;. &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%2FiPjvMaH.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%2FiPjvMaH.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2)&lt;strong&gt;Numbers&lt;/strong&gt;: A number can be an Integer or a Float. Integers are whole numbers, whereas Float contains a decimal. You can convert a string with a number inside into an Integer using &lt;em&gt;.to_i&lt;/em&gt; or a Float using &lt;em&gt;.to_f&lt;/em&gt;.&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%2FEhEFGfB.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%2FEhEFGfB.png" alt="Alt text of image"&gt;&lt;/a&gt;&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%2FE0HrzuZ.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%2FE0HrzuZ.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3)&lt;strong&gt;Booleans&lt;/strong&gt;: Booleans are used in logic statement to determine whether something is True or False. In Ruby, everything is True, but False and nil. We can use comparison operators such as &lt;em&gt;AND&lt;/em&gt;, &lt;em&gt;OR&lt;/em&gt;, &lt;em&gt;==&lt;/em&gt;, &lt;em&gt;||&lt;/em&gt;, &lt;em&gt;&amp;amp;&amp;amp;&lt;/em&gt;&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%2FgHyNxfG.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%2FgHyNxfG.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4)&lt;strong&gt;Symbols&lt;/strong&gt;: In Ruby a symbol is an object that represents names of instance variables, names of method, or names of classes. If there is a hello method, then there is a symbol &lt;em&gt;:hello&lt;/em&gt;. You can call on a symbol anywhere in the app or program. You can convert a string into a symbol using &lt;em&gt;.to_sym&lt;/em&gt;.&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%2FJ71Cayf.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%2FJ71Cayf.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5)&lt;strong&gt;Arrays&lt;/strong&gt;: Array is a list that can consist of all different kinds of data types. It is enclosed in square brackets &lt;em&gt;[]&lt;/em&gt;. There are different ways you can create an array.&lt;/p&gt;

&lt;p&gt;One way is by hard-coding it.&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%2FmMFke2E.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%2FmMFke2E.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another way is by using Array()&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%2F1PPIHxJ.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%2F1PPIHxJ.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6)&lt;strong&gt;Hashes&lt;/strong&gt;: A hash is a key, value pair enclosed in curly brackets &lt;em&gt;{}&lt;/em&gt;. They works like dictionaries, you can search for values by looking up the key and vice versa. There are also different ways you can create a hash.&lt;/p&gt;

&lt;p&gt;One way is by hard-coding it.&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%2FYXu3thb.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%2FYXu3thb.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another way is by assigning a variable to Hash.new&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%2FMlnOS3f.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%2FMlnOS3f.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are the Ruby data types to get you started on your Ruby adventure. Happy coding!  &lt;/p&gt;

</description>
      <category>ruby</category>
    </item>
    <item>
      <title>Building a Basic MVC App With Rails</title>
      <dc:creator>wenglin1</dc:creator>
      <pubDate>Thu, 20 Feb 2020 04:55:24 +0000</pubDate>
      <link>https://forem.com/wenglin1/building-a-basic-mvc-app-with-rails-5757</link>
      <guid>https://forem.com/wenglin1/building-a-basic-mvc-app-with-rails-5757</guid>
      <description>&lt;p&gt;What is rails? Rails is a Ruby framework built by multiple developers that makes building an app as easy as microwaving hot pockets. Ruby developers realized that there are a lot of repetitiveness when it comes to building a web application, so they compiled everything and made it easy to access and call upon with just a few lines of code. Why say lots of words when few do the trick?&lt;/p&gt;

&lt;h1&gt;
  
  
  EVERYTHING DONE HERE WILL BE ON MAC AND VSCode
&lt;/h1&gt;

&lt;p&gt;First things first, you should have these programs already installed on your computer: SQLite&lt;/p&gt;

&lt;p&gt;Next if you have ruby already installed, you can use &lt;em&gt;gem install rails&lt;/em&gt; to install rails onto your desktop.&lt;/p&gt;

&lt;p&gt;Once you have everything installed and setup we will start building our basic web app.&lt;/p&gt;

&lt;p&gt;To create a new rails application, go to your desired directory, and in your terminal type: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rails new "name"&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;You can replace name with anything you want. Let all the files generate into your new "name" folder. Once it is done, you can change directory into your folder and open it using cd "name".&lt;/p&gt;

&lt;p&gt;When you open the folder, to the left you will see all the files and folders that rails generated for you, we will only be needing these: config/routes, db folder, app/controllers, app/views, app/models.&lt;/p&gt;

&lt;p&gt;Pick two models and their relationship to work on. I will make this app on albums and songs, with a one to many relationship. An album haves many songs, and each song only belongs to one album.&lt;/p&gt;

&lt;p&gt;First we generate our models with the name and attributes following it: (remember to always make our models PLURAL)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rails g model Albums name:string&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;rails g model Songs name:string duration:integer album_id:integer&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Albums has a name attribute, songs has name, duration, and the album_id. The album_id is very important!! This signifies our relationship, so that later when we call on to the album, we can locate all the songs that belongs to the album. This will create new a folder called migrate in your db folder, and two new files in your app/models folder. &lt;/p&gt;

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

&lt;p&gt;Type &lt;strong&gt;rails db:migrate&lt;/strong&gt; to create our schema. &lt;/p&gt;

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

&lt;p&gt;This also creates our table. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;DO NOT TOUCH THIS FILE, LEAVE IT AS IS, IF YOU CHANGE SOMETHING IN THIS FILE, IT WILL CAUSE AN ERROR AND BREAK OUR TABLE.&lt;/strong&gt; If you want to add or delete an attribute, you can delete schema and the development file and remigrate. &lt;/p&gt;

&lt;p&gt;Next we have to establish our relationship, we go into our app/models folder, we'll see Album.rb and Song.rb. &lt;br&gt;
In Album type &lt;em&gt;has_many :songs&lt;/em&gt; to show an album can have many songs. &lt;/p&gt;

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

&lt;p&gt;In Song.rb type &lt;em&gt;belongs_to :album&lt;/em&gt; to show that a song belongs to only one album.&lt;/p&gt;

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

&lt;p&gt;Next we make our controllers, this will also establish our view folders and files. We only need some of the routes for our Album controller, show, and index. In your terminal type: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rails g controller Albums show index --no-test-framework&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The show and index keys generates our routes and view files. The "--no-test-framework" stops rails from generating extra test files. For our Song controller we dont need any routes right now. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rails g controller Songs --no-test-framework&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;This will create new files in app/controller.&lt;/p&gt;

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

&lt;p&gt;Inside the Album file, it will look like this: &lt;/p&gt;

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

&lt;p&gt;Song file, will look like this:&lt;/p&gt;

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

&lt;p&gt;Our app/view folder will have new folders and files.&lt;/p&gt;

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

&lt;p&gt;Next we will head to config/routes file and replace the routes rails generated for us with:&lt;/p&gt;

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

&lt;p&gt;Now we can open our web app by typing in our terminal&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rails s&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can access the homepage by going to &lt;em&gt;localhost:3000&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;Now if you head into localhost:3000/albums you will see this:&lt;/p&gt;

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

&lt;p&gt;This just means we didn't put anything in our views file for album/index. Press &lt;em&gt;control + c&lt;/em&gt; in the terminal to close our app.&lt;/p&gt;

&lt;p&gt;First lets write out all our controller actions in album. &lt;/p&gt;

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

&lt;p&gt;Index will show all the albums we have, and show will display all the songs each albums have. &lt;/p&gt;

&lt;p&gt;Before we edit our views files, we should write out some seed data so that we can display our album and songs when we visit the urls. &lt;/p&gt;

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

&lt;p&gt;Once we have our seed data, type in the terminal:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rails db:seed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now lets go to the view files, we will start with &lt;em&gt;views/albums/index&lt;/em&gt;, we have to iterate over albums so that it will display all of it.&lt;/p&gt;

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

&lt;p&gt;I added some html tags to make it look neater. The link_to will let each name be clickable.&lt;/p&gt;

&lt;p&gt;If we run rails s again, localhost:3000/albums will look like this:&lt;/p&gt;

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

&lt;p&gt;Next we edit &lt;em&gt;views/albums/show&lt;/em&gt; to display all the songs each album has like so:&lt;/p&gt;

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

&lt;p&gt;The good thing about rails is that we don't have to restart our app everytime we change something. It will automatically update for us everytime we save the file. When we click on one of the album names, it should bring us to the album's page, and the page should look like this:&lt;/p&gt;

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

&lt;p&gt;Congratulations, you successfully built a simple MVC web app with rails. Next blog I will go into more detail on how to create, update, and deleting our data. &lt;/p&gt;

&lt;p&gt;Here are some more resources:&lt;br&gt;
&lt;a href="https://guides.rubyonrails.org/v5.0/getting_started.html"&gt;https://guides.rubyonrails.org/v5.0/getting_started.html&lt;/a&gt;&lt;br&gt;
&lt;a href="http://www.restular.com/"&gt;http://www.restular.com/&lt;/a&gt;&lt;/p&gt;

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