<?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: Anthony Mendoza</title>
    <description>The latest articles on DEV Community by Anthony Mendoza (@antman).</description>
    <link>https://dev.to/antman</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%2F385119%2Fb55b0c76-1e3b-48db-876e-fb9a63639eee.jpeg</url>
      <title>DEV Community: Anthony Mendoza</title>
      <link>https://dev.to/antman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/antman"/>
    <language>en</language>
    <item>
      <title>Leetcode #98 (validate binary search tree)</title>
      <dc:creator>Anthony Mendoza</dc:creator>
      <pubDate>Wed, 23 Dec 2020 18:49:08 +0000</pubDate>
      <link>https://dev.to/antman/leetcode-98-validate-binary-search-tree-51df</link>
      <guid>https://dev.to/antman/leetcode-98-validate-binary-search-tree-51df</guid>
      <description>&lt;p&gt;Hi! &lt;br&gt;
I wanted to share my answer to a really cool problem I came across on leetcode. I want to do it a bit differently, I want to first share a sort of pseudocode/steps for anyone kind of stuck that wouldn't want the answer right away.&lt;/p&gt;

&lt;h3&gt;
  
  
  - The problem
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Given the root of a binary tree, determine if it is a valid binary search tree (BST).&lt;br&gt;
A valid BST is defined as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The left subtree of a node contains only nodes with keys &lt;strong&gt;less than&lt;/strong&gt; the node's key.&lt;/li&gt;
&lt;li&gt;The right subtree of a node contains only nodes with keys &lt;strong&gt;greater than&lt;/strong&gt; the node's key.&lt;/li&gt;
&lt;li&gt;Both the left and right subtrees must also be binary search trees.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;This is what a binary search tree should look like&lt;/strong&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%2Fcdn.programiz.com%2Fsites%2Ftutorial2program%2Ffiles%2Fbst-vs-not-bst.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%2Fcdn.programiz.com%2Fsites%2Ftutorial2program%2Ffiles%2Fbst-vs-not-bst.png" alt="BFS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Anything on the left must be less than the parent and anything on the right must be bigger than the parent.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  - Thoughts / Questions
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Some things to keep in mind if you were asked this during an interview. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h6&gt;
  
  
  Questions
&lt;/h6&gt;

&lt;ol&gt;
&lt;li&gt;What would the output need to be (this case leetcode gives it to use and it is a boolean. )&lt;/li&gt;
&lt;li&gt;I would if possible draw out a BST and a tree to confirm the question. &lt;/li&gt;
&lt;li&gt;What are we given in the function. ( head, value, left, right?)&lt;/li&gt;
&lt;/ol&gt;

&lt;h6&gt;
  
  
  Thought process
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;For this Problem I want to first traverse the tree inOrder and add the values to an array. By doing this we will have all the values in order. &lt;/li&gt;
&lt;li&gt;Next I want to run a loop to check if the value at our current index is bigger or equal to the next value. if it is we return false because we know this is not a valid BST.&lt;/li&gt;
&lt;/ul&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%2Fwww.java2blog.com%2Fwp-content%2Fuploads%2F2014%2F07%2FInOrderTraversalBinaryTree-1.jpg" 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%2Fwww.java2blog.com%2Fwp-content%2Fuploads%2F2014%2F07%2FInOrderTraversalBinaryTree-1.jpg" alt="InOrder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;With InOrder Our output will be in order. Meaning we are grabbing the lowest value first and working our way up.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Looking at the picture above you can see if a value before hand is bigger there is no way this is a valid BST.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  - Steps
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;This is going to be a more indepth walkthrough of our problem. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;In our leetcode problem we are only given access to the root. &lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;First We need to traverse our given tree using DFS Inorder.&lt;/li&gt;
&lt;li&gt;Create a variable to store the values of nodes that we visited.&lt;/li&gt;
&lt;li&gt;Write a helper function called traverse which accepts a node.

&lt;ul&gt;
&lt;li&gt;If the node has a left property, call the helper function with the left property on the node. &lt;/li&gt;
&lt;li&gt;Push the values of the node to the variable that stores the values.&lt;/li&gt;
&lt;li&gt;If the node has a right property, call the helper function with the right property on the node. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Invoke the helper function with the given root.&lt;/li&gt;
&lt;li&gt;Using the visited array we can write a for loop on the length of the array. &lt;/li&gt;
&lt;li&gt;In the loop we can write an if statement to check if the value at our current index is bigger than the next value if it is we can return false. &lt;/li&gt;
&lt;li&gt;after the loop runs we can return true because this means no value beforehand was bigger. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  - The code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const isValidBST = root =&amp;gt; {    
 let results = []; 

 const traverse = tree =&amp;gt;{
  if(!tree) return null 
  if(tree.left) traverse(tree.left)
  results.push(tree.val)
  if(tree.right) traverse(tree.right)
 }
 traverse(root)

 for(let i = 0; i &amp;lt; results.length; i++){
    if(results[i] &amp;gt;= results[i + 1]) return false
 }
return true

};

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

&lt;/div&gt;



&lt;p&gt;Hope this was helpful! &lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>leetcode</category>
      <category>interviewprep</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Working with Controlled Forms In React</title>
      <dc:creator>Anthony Mendoza</dc:creator>
      <pubDate>Wed, 29 Jul 2020 05:37:48 +0000</pubDate>
      <link>https://dev.to/antman/working-with-controlled-forms-in-react-2kjo</link>
      <guid>https://dev.to/antman/working-with-controlled-forms-in-react-2kjo</guid>
      <description>&lt;p&gt;Working with forms in React can be a bit daunting at first especially if it needs to make its way to your Back-end. Today I'm gonna try to make the process easier, we are going to be building out a form for a new user account.&lt;/p&gt;

&lt;h5&gt;
  
  
  1. Functional Component Or Class Component?
&lt;/h5&gt;

&lt;p&gt;To start we need to know if we are going to be keeping state or lifecycle methods in this component. For this particular component, we are gonna need state to keep track of the user input. Making this component a class component like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

class SignUp extends React.Component {
    state = {
        email: '',
        password: '',
        passwordConfirmation: '',
        firstName: '',
        lastName: ''

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

&lt;/div&gt;



&lt;h5&gt;
  
  
  2. Our Form
&lt;/h5&gt;

&lt;p&gt;In our Return, we need to write our form in JSX. To keep our code DRY, we are going to add a few more things to our form to save us time down the road.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;h3 className='signup-header'&amp;gt;Sign up!&amp;lt;/h3&amp;gt;
   &amp;lt;form onSubmit={this.handleSubmit}&amp;gt;
    &amp;lt;input
         name='email'
     value={this.state.email}                        
         onChange={this.handleChange}                        
         type='text'                         
         placeholder='Email'
       /&amp;gt; 
       &amp;lt;br&amp;gt;&amp;lt;/br&amp;gt;

     &amp;lt;input
     name='firstName'
         value={this.state.firstName}                        
         onChange={this.handleChange}                        
         type='text'
     placeholder='first name...'
      /&amp;gt;
      &amp;lt;br&amp;gt;&amp;lt;/br&amp;gt;

    &amp;lt;input
     name='lastName'
     value={this.state.lastName}
         onChange={this.handleChange}
     type='text'
     placeholder='last name...'
     /&amp;gt;
     &amp;lt;br&amp;gt;&amp;lt;/br&amp;gt;

    &amp;lt;input                       
         name='password'
         value={this.state.password}
     onChange={this.handleChange}
     type='password'
     placeholder='password'
    /&amp;gt;

    &amp;lt;input
    name='passwordConfirmation'
    value={this.state.passwordConfirmation}
    onChange={this.handleChange}
    type='password'
    placeholder=' confirm password'
    /&amp;gt;

    &amp;lt;button type='submit' class='btn btn-primary'&amp;gt;
    Sign Up
    &amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So whats going on with our form? first, by us setting our inputs with an attribute of 'name' we can play around with our event listener as I will show you in a bit. Secondly, our value attribute is what will make sure that our input and state are in sync leaving state as a single source of truth.&lt;br&gt;
Next up our 'onChange' is our event listener, in this case, we need to keep track of anything the user types in and we are tying this to our handle change function that I will show next. The next key part of our form is our button to submit. Make sure that it is set to &lt;code&gt;type=' submit'&lt;/code&gt;, so our submit handler can keep track of it. &lt;/p&gt;
&lt;h5&gt;
  
  
  3. Our Functions
&lt;/h5&gt;

&lt;p&gt;First, we need to keep track of our input and this is where adding that name attribute to our form will save us a lot of typing. When adding the name attribute to a form make sure 100% that it is exactly how it's written in our state if not nothing will get updated. I'm going to show you both ways without a name and with a name.&lt;/p&gt;
&lt;h5&gt;
  
  
  Without name attribute on form
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;handleEmail(event) {
    this.setState({email: event.target.value});
  }

handleFirstName(event) {
    this.setState({firstName: event.target.value});
  }

handleLastName(event) {
    this.setState({lastName: event.target.value});
  }

handlePassword(event) {
    this.setState({password: event.target.value});
  }

handlePasswordConfirmation(event) {
    this.setState({passwordConfirmation: event.target.value});
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  With a name attribute on form
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;handleChange = e =&amp;gt; {
        console.log(e.target.value);
        this.setState({ [e.target.name]: e.target.value });
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;By doing this we are setting our state to the name that was passed in and the value would be whatever user input is typed in.  &lt;/p&gt;
&lt;h5&gt;
  
  
  4. Handling our submits
&lt;/h5&gt;

&lt;p&gt;Lastly, we need to handle where our forms will go. For this, I will send a 'POST' request, for this work we will need to add a submission to the very top of our form &lt;br&gt;
&lt;code&gt;&amp;lt;form onSubmit={this.handleSubmit}&amp;gt;&lt;/code&gt; and our handle submit function will look like so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;handleSubmit = e =&amp;gt; {
let { email, password, passwordConfirmation, firstName, lastName} = this.state

e.preventDefault();

if (password === passwordConfirmation) {
fetch('http://localhost:3000/signup', {
  method: 'POST',
   headers: {
    'Content-Type': 'application/json',
     Accept: 'application/json',
    },
body: JSON.stringify({
           email, 
           password, 
           passwordConfirmation, 
           firstName, 
           lastName
    }),
    })
    .then(resp =&amp;gt; resp.json())
    .then(data =&amp;gt; {
         this.setState({
        email: '',
        password: '',
        passwordConfirmation: '',
        firstName: '',
        lastName: ''
         //with the data we can update our front-end
         //redirect here
      });
     })
        } else{
           alert("Passwords don't match!");
          }
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So to begin, using some es6 magic we can deconstruct our states to just their names and if those names match what is on your database in our body we can just write it one time and should work as long as the names match. Next, we need to make sure we don't prompt a refresh of the page and we can do so by adding a &lt;code&gt;.preventDefault&lt;/code&gt; the next part is not needed to submit a form but I wanted to check that password and password confirmation are the same if not give an alert that passwords don't match. lastly, we make our fetch and reset the form by setting the state back to blank. &lt;/p&gt;

&lt;p&gt;Hopefully I was able to be of some help when researching forms for react. :)&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>Syntactic Differences Between Ruby and Javascript</title>
      <dc:creator>Anthony Mendoza</dc:creator>
      <pubDate>Fri, 10 Jul 2020 05:47:03 +0000</pubDate>
      <link>https://dev.to/antman/syntactic-differences-between-ruby-and-javascript-54k9</link>
      <guid>https://dev.to/antman/syntactic-differences-between-ruby-and-javascript-54k9</guid>
      <description>&lt;p&gt;So you're learning Javascript coming from only knowing Ruby or vice-versa. In this post, I'm going to go over some of the syntactic differences that confused me at the beginning of my javascript journey. Before we start I want to mention that I love both languages with ruby's syntax almost being like reading plain English and javascript being so flexible in how it lets you work. With that being said let's begin as any rubyist would know most of our code would be wrapped in a 'def'/ method. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;methods&lt;/em&gt;
&lt;/h4&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvst4mh47h3onk01n6ovi.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%2Fvst4mh47h3onk01n6ovi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Any method in Ruby needs to start with a 'def' and always end with an 'end' and () as parameters. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7r5cmflkmuz9corck2yr.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%2F7r5cmflkmuz9corck2yr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Javascript's way of defining a function is a bit different for starters it's much more strict with its syntax while in ruby we don't need any brackets to write our code inside of it but we need and 'end' a good way to think about it is 'end == {}'. &lt;/p&gt;

&lt;p&gt;Moving on to another huge difference that may be hard to catch at first sight is template literals while this is not strictly bound to a function it's still a huge difference. In ruby, you can pass in information using "#{}" or '#{}' while in javascript the only way to use a template literal is using a grave accent/backticks ${} you are not given the freedom to choose with javascript so beware.&lt;/p&gt;

&lt;p&gt;Another way of writing functions in javascript that was recently introduced in ES6 is arrow functions personally to me these are very compact and easier to write. From my knowledge, there is a couple of differences in functionality so move forward with caution.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjlwdelvqizws4kcjnml9.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%2Fjlwdelvqizws4kcjnml9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Variables&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;Ruby has a couple of different types of variables which you will 1000% use, such as (global, class, and instance variables) but for purposes of comparison, I'm only going to show local variables and how to declare one in ruby. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffuyq2z0nyihiobkcz5hp.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%2Ffuyq2z0nyihiobkcz5hp.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Ruby's variable declaration is super straight forward give me a name and store the information you need in here, Javascript, on the other hand, likes to give you a couple of choices. &lt;/p&gt;

&lt;p&gt;The most common way and oldest way of declaring a variable is using good ol 'var'&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh37hkai0ec05jt881pn0.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%2Fh37hkai0ec05jt881pn0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
var is super basic and a staple of javascript a couple of things to know about var is that you can always change its value and it's on the global variable spectrum once declared it will be hoisted to the top of the page allowing room for some bugs, once again proceed with caution.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgcvyvawsb6g4nfl3d64d.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%2Fgcvyvawsb6g4nfl3d64d.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
"let" is a lot like var but one key difference is unlike var it won't be hoisted to the top of your page (usual safe bet to use).&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbsqczz1ae8xywwesk57o.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%2Fbsqczz1ae8xywwesk57o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
last but not least is const, one of the most strict. Once assigned if you try to change it you will produce an error saying it has been assigned. When using const use it for values that won't change.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Each loop&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;One of the last Syntactic differences I will cover for now is the use of .each or forEach.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Feyrqeejj57jv7qkq2tki.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%2Feyrqeejj57jv7qkq2tki.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Ruby's .each loop is almost like reading English it's a very easy way to loop through information the |list| is the parameters to give the loop and once again like most things it ruby you need to give it an "end".  &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpo0vgzgwv60hkypsoumo.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%2Fpo0vgzgwv60hkypsoumo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Javascript also makes it's for each loop very easy to read minus the end to finish it off. I hope this helps anyone learning any of these languages to differentiate some the syntax :).&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Using Bootstrap 4 In Rails 6</title>
      <dc:creator>Anthony Mendoza</dc:creator>
      <pubDate>Thu, 18 Jun 2020 05:14:29 +0000</pubDate>
      <link>https://dev.to/antman/using-bootstrap-4-in-rails-6-39hk</link>
      <guid>https://dev.to/antman/using-bootstrap-4-in-rails-6-39hk</guid>
      <description>&lt;p&gt;Using Bootstrap in a Rails app can be very confusing at first to help make things easier and smoother and allow you to go back to developing, I'm going to try and help you get started with Bootstrap.&lt;br&gt;
We are going to start from a point where you already have a rails app up as far as (views, controllers, models, and some data ).&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;em&gt;Getting Started&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;You first need to head on over to &lt;a href="https://github.com/twbs/bootstrap-rubygem"&gt;https://github.com/twbs/bootstrap-rubygem&lt;/a&gt; and grab these 2 gems as shown below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9r7U5XVS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/le90z9rxn4t13nx4fafv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9r7U5XVS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/le90z9rxn4t13nx4fafv.png" alt="Alt Text" width="257" height="41"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EHGCaJ5D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8b1e18zog9arhxo4apse.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EHGCaJ5D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8b1e18zog9arhxo4apse.png" alt="Alt Text" width="179" height="29"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;once you've copied them take them over to your gemfile which if you havent used yet I will provide a screenshot of the location.&lt;/p&gt;

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

&lt;p&gt;Go ahead and paste them and save the file or hit "cmd + s"&lt;/p&gt;

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

&lt;p&gt;Switch over to your terminal make sure you are in the right directory for your app go ahead and type 'bundle' or 'bundle install'. This will add the gems to your app and add it to your gemfile lock, don't worry too much about it for now but what it's doing is locking in the version of your gems you have installed so you don't have to worry about  gem updates messing up your app. It may take a while to load but just be patient :).&lt;/p&gt;

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

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

&lt;p&gt;Once done there's still a couple more steps we need to take before we are all setup. Next you need to go to your &lt;br&gt;
app/assets/stylesheets/application.scss if it's a .css file go ahead and make it a .scss but it should default to .scss&lt;/p&gt;

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

&lt;p&gt;Inside the application.scss go ahead and paste.&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="vi"&gt;@import&lt;/span&gt; &lt;span class="s2"&gt;"bootstrap"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we need to go to our app/javascript/packs/application.js folder and paste the code below. After you've done so you're ready to build the next Twitter! well not just yet, I'm going to show you how to use it.&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="sr"&gt;//&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="n"&gt;jquery3&lt;/span&gt;
&lt;span class="sr"&gt;//&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="n"&gt;popper&lt;/span&gt;
&lt;span class="sr"&gt;//&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="n"&gt;bootstrap&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sprockets&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;em&gt;Using Bootstrap&lt;/em&gt;
&lt;/h3&gt;

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

&lt;p&gt;How do we go from the picture above to the picture below. &lt;/p&gt;

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

&lt;p&gt;Most importantly making the page take in user input and storing that instance into our Database. I'm going to be showing you how to make a simple sign-up page that not only looks super neat but works. Once again I'm taking into account you have a working form and your controllers and routes are working and focus solely on making it pop!&lt;/p&gt;

&lt;p&gt;Rails has some pretty cool helpers to ease making a functional form I'm going to be linking it below!&lt;/p&gt;

&lt;p&gt;What these Helpers will do is help us by writing out some of that HTML for us, so let's get started. &lt;/p&gt;

&lt;p&gt;Let's say we are making a form_for a @user to signup our initial syntax may look like &lt;/p&gt;

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

&lt;p&gt;This is where Bootstrap comes in to save the day. We are going to be using one of Bootstraps classes to help us &lt;/p&gt;

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

&lt;p&gt;So then we will begin to add some of the attributes that are required for this form in my instance it was a couple of things but this can vary for you. So how do we keep this layout consistent for all the attributes. Bootstrap and Rail helpers make this extremely easy, like so. &lt;/p&gt;

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

&lt;p&gt;There's a lot going on here but if we break it down it's really clear to understand.&lt;/p&gt;

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

&lt;p&gt;So our f.label and f.text_field is us using our Rails helpers to let our controller know this is what is going to be entered here. Next to it is us letting bootstrap know we are still using their form and next is just a place holder that will delete once you begin typing.  {class:"form-control", placeholder:"Enter name"} &lt;/p&gt;

&lt;p&gt;It may seem like a lot but 1) Our Rails helper is just making our HTML easier to write. 2) The Bootstrap is helping us with our CSS and HTML. If we inspect our Page you can see the same name form being rendered into plain HTML.&lt;/p&gt;

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

&lt;p&gt;Once done you can end your form with a simple button provided by Bootstrap. Once submitted it will enter the data into your database working way better than a simple HTML form. &lt;/p&gt;

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

&lt;p&gt;I'm going to place some links below to the Bootstrap documentation which I highly encourage you to read and play around with and watch your application come to life. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://guides.rubyonrails.org/form_helpers.html"&gt;https://guides.rubyonrails.org/form_helpers.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://getbootstrap.com/docs/4.5/getting-started/introduction/"&gt;https://getbootstrap.com/docs/4.5/getting-started/introduction/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>css</category>
    </item>
    <item>
      <title>Relationship Models in Ruby</title>
      <dc:creator>Anthony Mendoza</dc:creator>
      <pubDate>Sun, 24 May 2020 17:33:34 +0000</pubDate>
      <link>https://dev.to/antman/relationship-models-in-ruby-24pd</link>
      <guid>https://dev.to/antman/relationship-models-in-ruby-24pd</guid>
      <description>&lt;p&gt;Coming into Flatiron's Software Engineering program the biggest topic I struggled with was relationship models and how it all came together. As I quickly realized having a good grip on this is probably one of the most important topics in mod1. In an effort to try to help as many future cohorts that struggle with this topic and anyone trying to learn OOP, ORM's or ActiveRecord I'm going to go over some models and tips on how to read a README and be able to clearly understand the relationships. Let's begin!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ayo5DMff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3ia2ywlbkngc1eiqij99.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ayo5DMff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3ia2ywlbkngc1eiqij99.gif" alt="Alt Text" width="500" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before you begin coding I cannot stress it enough to have a notebook nearby or as I will be using a virtual whiteboard that can be found &lt;a href="https://awwapp.com"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;One-to-Many&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;One of the first models you will come across is the one-to-many model. With this model in some README's you will get something along the lines of "A &lt;strong&gt;classroom has many students&lt;/strong&gt; but a &lt;strong&gt;student has only one classroom&lt;/strong&gt;" some keywords to look out for are "belongs to" or "can only have one". So you may be asking yourself how do we translate this into code, well let's begin with our handy notebook first. We are going to use the "Student" and "Classroom" model.&lt;/p&gt;

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

&lt;p&gt;Let's say we initialize with our classroom class only having a "room number" and our student class with a "grade" and a "name". &lt;/p&gt;

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

&lt;p&gt;As seen above I've already drawn out that a classroom can have many students. So what's next? well, we know our student class can only have one classroom so who inherits what here? &lt;/p&gt;

&lt;p&gt;First I'm going to show you the wrong way of doing this and then explain why you should never do this. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y3OKB7pL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v2pk0q53yb6diixmujoq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y3OKB7pL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v2pk0q53yb6diixmujoq.png" alt="Alt Text" width="880" height="252"&gt;&lt;/a&gt;&lt;br&gt;
Doesn't look too bad right? well what if we need another student and another student just got enrolled for your class as I'm typing this, it would look something like this.&lt;/p&gt;

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

&lt;p&gt;Keep in mind this is just one instance of a classroom what if a less popular classroom had fewer students.&lt;/p&gt;

&lt;p&gt;This not only would break our program but cause a huge amount of bugs in our database. You can see that the program would break by us just trying to initialize it. So what's a good rule of thumb to go by? when speaking to one of my coaches he gave me a tip that stuck with me and it is.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"in a parent-child relationship, the child will always have a reference to the parent. Kind of like passing genes. The parent is what has many of something the child belongs to a parent. The child will always have a reference to the parent."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So what would be the correct way of doing this? &lt;/p&gt;

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

&lt;p&gt;Every instance of a student would be initialized with the classroom_id as it's inheriting from our parent class. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Many-to-Many&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;So let's say our app is getting an update now a student can have many classrooms so first off some keywords to look out for in this relationship is "A classroom &lt;em&gt;has many students&lt;/em&gt; and a &lt;em&gt;student can have many classrooms&lt;/em&gt;" let's start again with the empty whiteboard on how this would look.&lt;/p&gt;

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

&lt;p&gt;Once again I'm going to show you the wrong way of going about this first.&lt;/p&gt;

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

&lt;p&gt;Doesn't look too bad right? but as stated in the README "have many" both can have many of each other. So, in reality, our program would look something like this.&lt;/p&gt;

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

&lt;p&gt;Once again breaking our program and our database. So how do we fix this? &lt;br&gt;
We add a join table/class. A table or class that will keep just track of this for us. &lt;/p&gt;

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

&lt;p&gt;So now every time an instance of a student that has multiple classrooms or vice versa it will be initialized there with no problems and zero bugs. This can get very deep and you can have multiple join classes for different occasions but once you get the basic understanding of why things are placed where they are, it will make your job a whole lot easier. I hope this helps :)!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jUdtgRDk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dtukxsff4vrnz6z06v5o.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jUdtgRDk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dtukxsff4vrnz6z06v5o.gif" alt="Alt Text" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>database</category>
      <category>oop</category>
    </item>
  </channel>
</rss>
