<?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: lycho33</title>
    <description>The latest articles on DEV Community by lycho33 (@lycho33).</description>
    <link>https://dev.to/lycho33</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%2F578744%2F35042012-c96f-4f62-a40f-69765a5a72a2.png</url>
      <title>DEV Community: lycho33</title>
      <link>https://dev.to/lycho33</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lycho33"/>
    <language>en</language>
    <item>
      <title>Redux vs Ruby</title>
      <dc:creator>lycho33</dc:creator>
      <pubDate>Thu, 16 Dec 2021 20:33:24 +0000</pubDate>
      <link>https://dev.to/lycho33/redux-vs-ruby-3agc</link>
      <guid>https://dev.to/lycho33/redux-vs-ruby-3agc</guid>
      <description>&lt;p&gt;There are two parts to redux: a reducer and action. An action is where you can fetch data from an API and get access to the backend's current state. A reducer on the otherhand gets to determine how the state will be updated on the frontend. &lt;/p&gt;

&lt;p&gt;For my project, I was trying to create a mini-ecommerce website. The project was simple. I was going to have a store with projects and have a button that could add a product to a cart. It should have been simple until I reached the reducer.....&lt;/p&gt;




&lt;p&gt;In RUBY my settings were:&lt;/p&gt;

&lt;p&gt;An API, which had...&lt;/p&gt;

&lt;p&gt;Routes: &lt;/p&gt;

&lt;p&gt;resources :cart do&lt;br&gt;
     --resources :purchase_carts&lt;br&gt;
end&lt;br&gt;
resources :products&lt;/p&gt;

&lt;p&gt;In REDUX...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the ACTION fetched to get products, get a cart and ADD a product to the cart
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   export const addProductToCart = (obj) =&amp;gt; {
    return (dispatch) =&amp;gt; fetch("http://localhost:4000/cart/1/purchase_carts", {
        method: "POST",
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(obj),
    })
        .then(r =&amp;gt; r.json())
        .then(addedProducts =&amp;gt; {
            dispatch({
                type: "ADD_PRODUCTS",
                payload: addedProducts
            })
        })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;REDUCER contained this code...
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function reducer(state= intialState, action){
    switch (action.type){
        case "GET_PRODUCTS":
            return {...state, products: [...action.payload]}
        case "GET_CART":
            return {...state, cart: [...action.payload]}
        case "ADD_PRODUCTS":
            const updatedCart = {
                ...state.cart[0],
                purchase_carts: [...state.cart[0].purchase_carts, action.payload]
            }
            return {
                ...state,
                cart:[updatedCart]
            }
        default:
            return {...state}
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything looks okay.... but when testing... the product would not add more than 1 to the cart. &lt;/p&gt;

&lt;p&gt;On the frontend, everything in REDUX and in my components were coded to function the way I designed it. In the reducer, the would return with all the state already included, plus a key-value pair of cart and updatedCart. This updatedCart would show everything in the state's first cart, then create another key-value pair for purchase_carts and create an array with all the state's first cart's purchase_carts and all information from the component's form which was posted into the backend's API and retranslated as the "action.payload." &lt;/p&gt;

&lt;p&gt;So what was wrong?&lt;/p&gt;

&lt;p&gt;What I discovered was the problem was so..... simple. In RUBY, my routes had purchase_carts inside of cart. So to see this on localhost:3000, I needed to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;include: :purchase_cart ---&amp;gt; in the index and show methods&lt;/li&gt;
&lt;li&gt;include :purchase_cart in the attributes for my models&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;THAT'S IT!&lt;/p&gt;

&lt;p&gt;Why did I have to do this? &lt;br&gt;
In my reducer, I wanted to add all information from my form into purchase_cart which was my joins table so that my cart could have access to the product (which was also inside the joins table). But to access purchase_cart it needed to show it was properly posted in my API before the state could be properly updated on the frontend. &lt;/p&gt;

&lt;p&gt;LESSON?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Before you play with the frontend, check the backend! &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>rails</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Fetch Boi</title>
      <dc:creator>lycho33</dc:creator>
      <pubDate>Sat, 05 Jun 2021 18:38:43 +0000</pubDate>
      <link>https://dev.to/lycho33/fetch-boi-nca</link>
      <guid>https://dev.to/lycho33/fetch-boi-nca</guid>
      <description>&lt;p&gt;The concept of Fetch is simple. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get data from an API address&lt;/li&gt;
&lt;li&gt;Parse the response into JSON &lt;/li&gt;
&lt;li&gt;From the given data, iterate to manipulate in the backend and frontend and render it on DOM. &lt;/li&gt;
&lt;li&gt;Just in case, console an error to see on the browser any possible errors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you just practice fetch a few times, the concept is easier than you think. So why did I struggle so much on something so simple? &lt;/p&gt;

&lt;h3&gt;
  
  
  FIRST: Flow
&lt;/h3&gt;

&lt;p&gt;After doing Ruby, I was confident that this would be easy. However, I ran into confusion of the flow. What is the order to events?&lt;/p&gt;

&lt;p&gt;Scenario&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The browser listens for an event&lt;/li&gt;
&lt;li&gt;Call a function to listen for a click&lt;/li&gt;
&lt;li&gt;Manipulate to either CRUD or display on the browser&lt;/li&gt;
&lt;li&gt;fetch!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What did I struggle with? All the functions leading up to fetch.&lt;/p&gt;

&lt;h3&gt;
  
  
  SECOND: functions
&lt;/h3&gt;

&lt;p&gt;When you create variables to find an ID or create an element. The most confusing thing is trying to figure out when to put the variable inside the callfunction. &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const li = document.getElementById(`image-${this.id}`)&lt;br&gt;
   const ul = document.createElement(`ul`)&lt;br&gt;
   this.vocabularies.forEach(v =&amp;gt; ul.innerHTML += v.render())&lt;br&gt;
   li.append(ul)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Yes it's obvious now that I include 'ul' in "append" but for some reason it took a while for me to figure out that I wanted to put in new bullet points and not new "li". &lt;/p&gt;

&lt;h3&gt;
  
  
  THIRD: JS Objects
&lt;/h3&gt;



&lt;p&gt;&lt;code&gt;static handleSubmit(event){&lt;br&gt;
        event.preventDefault()&lt;br&gt;
        const input = event.target&lt;br&gt;
        let obj = [...input.elements]&lt;br&gt;
        let args = {image: {}}&lt;br&gt;
        args.image.category = obj[0].value&lt;br&gt;
        args.image.url = obj[1].value&lt;br&gt;
        fetchAll.createImage(args) &lt;br&gt;
    }&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This code right above is showing how to transform your input into an object, then call on the values for when you fetch. For the variable "args", I needed "image" as a key because the fetch wouldn't not work otherwise. In order to create a new Image, I would need the object to have the key "image" recognized, THEN I can add input for the columns for the Image model.  &lt;/p&gt;

&lt;h3&gt;
  
  
  FOURTH: Show up on the Page!
&lt;/h3&gt;

&lt;p&gt;When creating the delete image functions/fetch, it was difficult to figure how to get the browser to also delete the image without need to refresh the page. &lt;/p&gt;

&lt;p&gt;The problem?&lt;br&gt;
For fetch, I put &lt;code&gt;li.remove()&lt;/code&gt;. So wouldn't it "remove" the picture from the page? Apparently not. I needed to put this code again in my function for handling the delete. The very function that would find the "delete" button and call the fetch function. &lt;/p&gt;

&lt;p&gt;Solution&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;static handleDelete(e){&lt;br&gt;
        const li = e.target.parentElement&lt;br&gt;
        if (e.target.dataset.action === 'delete'){&lt;br&gt;
            fetchAll.deleteImage(li)&lt;br&gt;
            li.remove()&lt;br&gt;
    }&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;So here it is. A simple fetch that is easy to learn but difficult to implement on a single-page. I probably struggled since it was my first time trying JavaScript but all these roundabout problems taught me that I really need to work on logic flow. If I thought about each step slowly, perhaps I wouldn't have struggled with fetch as much as I did. But now I know and despite hours/days of struggle, I'm still excited to continue using JavaScript. For me, I feel like these problems are evolving me. Hope it does the same for you guys. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Associations</title>
      <dc:creator>lycho33</dc:creator>
      <pubDate>Tue, 04 May 2021 19:58:31 +0000</pubDate>
      <link>https://dev.to/lycho33/associations-26m2</link>
      <guid>https://dev.to/lycho33/associations-26m2</guid>
      <description>&lt;p&gt;After learning Ruby on Rails, I learnt that associations was the most crucial aspect, without it...nothing works.&lt;/p&gt;

&lt;h3&gt;
  
  
  Original Project
&lt;/h3&gt;

&lt;p&gt;The first project I created was supposed to be website where the user could be a student or mentor. If the user was a mentor, the mentor could create lessons but if the user was as student, the student would complete lessons. Simple? &lt;/p&gt;

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

&lt;p&gt;For an idea I thought was so simple, turned out to be far too complicated for me to handle. &lt;/p&gt;

&lt;h4&gt;
  
  
  Problem 1
&lt;/h4&gt;

&lt;p&gt;It was unnecessary to have 2 separate models for Students and Mentors. &lt;/p&gt;

&lt;p&gt;So I decided to combine them into Users. But this did not work because I was bypassing Separation of Concerns. A User model was supposed to only deal with login/signout/logout. Instead I created a separated model called Role so the User could choose it's role as either a mentor or student&lt;/p&gt;

&lt;h4&gt;
  
  
  Next Problem
&lt;/h4&gt;

&lt;p&gt;I wanted to create a many-to-many association but I had to combine my Student/Mentor model. By doing so I would have to create custom associations so that the Roles model could have a has_many association for Mentor and Student. &lt;/p&gt;

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

&lt;p&gt;This would not have been a problem but this would have taken a lot longer to understand and figure out. The project had to be completed in a week. What's worse was that I did not know how to use these custom associations in my controllers. Additionally, my primary/foreign keys were not working (due to my lack of understanding) which made my nested resources break and my routes not be designed correctly. &lt;/p&gt;

&lt;p&gt;So... I decided to SCRAP this project&lt;/p&gt;

&lt;h3&gt;
  
  
  THE NEW PROJECT
&lt;/h3&gt;

&lt;p&gt;The new project ended up being a website about an international violin competition called the Menuhin Competition 2021. This website would allow users to upload ongoing performances and blog about it. &lt;/p&gt;

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

&lt;p&gt;The benefit of these associations is that I can have a many-to-many association. &lt;/p&gt;

&lt;p&gt;For example: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Users has many performances they can upload but each uploaded performance belongs to a user&lt;/li&gt;
&lt;li&gt;A user can comment on any uploaded performance. Because comments is the joins table, user has many performances through comments. 
-A user can post a blog. So each blog belongs to a user but a user can post many blogs. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For me, this new project ended up have far simpler associations that I could comprehend. But I still hope as I continue to try deepen my understanding on associations that I can come back to the original project and try complete it. For now, I learnt the hard way how important associations are. &lt;/p&gt;

</description>
      <category>rails</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>I'm finally making a website!</title>
      <dc:creator>lycho33</dc:creator>
      <pubDate>Wed, 31 Mar 2021 02:07:33 +0000</pubDate>
      <link>https://dev.to/lycho33/i-m-finally-making-a-website-3p4j</link>
      <guid>https://dev.to/lycho33/i-m-finally-making-a-website-3p4j</guid>
      <description>&lt;p&gt;FINALLY!&lt;/p&gt;

&lt;p&gt;After working on a CLI app, I was still feeling murky, struggling to visualize how it's like creating a website. BUT finally I am creating a website like a full-stack developer!&lt;/p&gt;

&lt;p&gt;Honestly, this website was not easy since the learning curve was steep for me. What I struggled with.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;REST&lt;br&gt;
For some reason this was confusing for me. For example, I was creating a post for the get "/lesson/new". So I named it post "/lesson/new," but later I am told that this does not match REST. I was told that the post route was supposed to be "/lesson." Honestly, I am still confused about this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Associations&lt;br&gt;
I initially created a many-to-many relationship. But to stick to MVP, I decided to only have has-many and belongs-to relationships. By doing so, the tables I also initially migrated had become mixed up. I did notice this mistake until I was trying to create a "current_users" method. When trying to use this method, I would get an error on the browser saying "cannot find table 'join'." It was only then, I realized I had to go back and fix my tables and associations, which made me feel like I had to go back to square one. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Forms&lt;br&gt;
Forms shouldn't have been that hard but I learned the hard way that if you do not have the params and right variable, then your forms will not post the way it should. In my controllers, my local or instance variables would be called "lesson" while the params would be called "lessons." At one point, this became too confusing to the point the mix up gave me constant errors I would have to debug.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Styling&lt;br&gt;
I wanted to stay true to Separation of Concerns, but unfortunately CSS styling became difficult to do. In my public folder, I tried to create CSS files for each Views page but for some reason the style would not show on the browser, requiring me to directly style in HTML. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Here are all my struggles. Despite all of the challenges, I learnt so much more on debugging and how to become a better detective. More importantly, I became a better Googler. Instead of relying on my current knowledge, I solidified my habit to look up what I was unsure on and this helped a lot. &lt;/p&gt;

&lt;p&gt;Knowing that the next project will be another website makes me so excited and I can't wait to make a better one that will look more professional. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Cautionary Iterarty Tale</title>
      <dc:creator>lycho33</dc:creator>
      <pubDate>Thu, 11 Mar 2021 04:39:29 +0000</pubDate>
      <link>https://dev.to/lycho33/cautionary-iterarty-tale-blh</link>
      <guid>https://dev.to/lycho33/cautionary-iterarty-tale-blh</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F3FlS9qL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chjxcran2x77ny78e33h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F3FlS9qL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chjxcran2x77ny78e33h.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
For Flatiron, I was in Phase 1 starting to go through labs and learn about Ruby. Of course loops and conditionals had their own challenges to adjust to, iterations seemed simple. You iterate through an array so that the block of code is executed for each array's element. But only after finalizing my CLI project do I now understand the importance of iterators.&lt;/p&gt;

&lt;p&gt;Here is a list of iterators&lt;br&gt;
1) .each&lt;br&gt;
2) .map/.collect&lt;br&gt;
3) .select&lt;br&gt;
4) .detect&lt;br&gt;
5) .delete_if&lt;br&gt;
6) .find/.find_all&lt;/p&gt;

&lt;p&gt;OUT of all of these arrays I had to learn which iterators would be most helpful for my code. And this is what I learned. &lt;/p&gt;

&lt;h3&gt;
  
  
  .each
&lt;/h3&gt;

&lt;p&gt;This was deceivingly the most simple method. From numerous labs, I found that this method would be the most versatile to pass the labs. It allowed me to execute anything in the iteration bloc, while not easily breaking my program. &lt;/p&gt;

&lt;p&gt;I already knew that the return for .each was the original array. But despite knowing this, I used this method in my class to extract my API methods and gather specific data. By doing so, I was not keeping my code DRY and putting in .each iterations that weren't doing anything for my program. &lt;/p&gt;

&lt;h2&gt;
  
  
  So the key lesson I needed to learn:
&lt;/h2&gt;

&lt;p&gt;.each iterates over each array's element and executes the block's code BUT still returns the original array&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   ##IF each was not going to do anything what should I use?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  .map/.collect
&lt;/h3&gt;

&lt;p&gt;After calling my API and making it into a hash, my goal was to iterate to extract only a specific key and its associated values. So my next go-to would have been these methods. I was going to iterate to get the specific key-value pairs. And when I did... IT DIDN'T WORK!&lt;/p&gt;

&lt;p&gt;What does it return?&lt;br&gt;
    .map/.collect returns a new array BUT + collect/map TRANSFORMS every array's element and doesn't extract the specific key-value pairs I needed. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   ##SO what did I need?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  .select
&lt;/h3&gt;

&lt;p&gt;IT was this! Select returns a new array of elements that are true to the condition set in within the block. So if the key I needed matched the element, then it was TRUE and would be included in the new array. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  ##Question: Would .find_all had worked?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  .find_all
&lt;/h3&gt;

&lt;p&gt;After investigating further, .find_all might not have worked because when iterating through a hash, find_all would return an array whereas select would return a hash still. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ##What's the verdict of this challenge?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Lesson&lt;/strong&gt;: What return you want dictates what iterator you choose to use. It will be lesson not to forget. Though .each is versatile, it will not return a new array. So here is my cautionary tale that I hope others do not fall into. Heed my mistake and happy programming!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>cli</category>
      <category>programming</category>
    </item>
    <item>
      <title>Struggles to build a Ruby Project</title>
      <dc:creator>lycho33</dc:creator>
      <pubDate>Sat, 27 Feb 2021 23:47:37 +0000</pubDate>
      <link>https://dev.to/lycho33/struggles-to-build-a-ruby-project-5a15</link>
      <guid>https://dev.to/lycho33/struggles-to-build-a-ruby-project-5a15</guid>
      <description>&lt;p&gt;Debugging is such a journey. At the final leg of my project, I smirked that the code was running smoothly until my instructor found a small problem. &lt;/p&gt;

&lt;p&gt;My project's goal is to use the API's data to help you find the right type of brewery in your state and city. When you enter in the state you live in, it prints out 5 sample breweries in the state. &lt;/p&gt;

&lt;p&gt;Like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RfCw7k-A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jv5nyxjiqqwiuki4gn63.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RfCw7k-A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jv5nyxjiqqwiuki4gn63.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, after going through the whole code. The user is given the choice to return to "menu" or "exit." If the user chooses "menu," then the user can enter in a different state, city or type of brewery.&lt;/p&gt;

&lt;p&gt;The problem my instructor discovered was that the first 5 breweries you listed after typing in your state would stay on the list. So when you return to "menu" and enter another state, it would give the original 5 breweries, PLUS the next 5 breweries from the new state. &lt;/p&gt;

&lt;p&gt;-------------------HOW TO DEBUG THIS---------------------------------------&lt;br&gt;
For several hours, I used binding.pry to see where it would create a new list. In my API folder, I was using an instance method to grab the API's data as an array and separate the array into nested hashes. I used this method 3 times to grab data from the API's base URL, state URL and city URL. &lt;/p&gt;

&lt;p&gt;1st suspicion:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I used this instance method 3 times in my CLI. Once in my initializer. Second time when I was creating a list for the state the user entered. Third time was when I created a list for the city the user entered. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Approach:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Delete the instance method with the base URL because we are starting by looking for breweries in a specific state. &lt;/li&gt;
&lt;li&gt;Keep the instance method for the state&lt;/li&gt;
&lt;li&gt;Delete the instance method with the URL with the city because we are going to use the state URL to find the city, then the breweries in that city. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;SO it ends up looking like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i_lRmeGB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mm105ofota1sim7k5l9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i_lRmeGB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mm105ofota1sim7k5l9.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since I got rid of the other 2 API instance methods, I got rid of the methods in my CLI and Brewery class folder, which used the deleted API instance methods. &lt;/p&gt;

&lt;p&gt;Afterwards...Still the same problem&lt;br&gt;
       After doing all of this, the problem remains. &lt;br&gt;
       So I debug again. I put a binding.pry all over my CLI file &lt;br&gt;
         to see where my API method was repeating or being called &lt;br&gt;
         again so that the list of breweries for state is &lt;br&gt;
         duplicated. &lt;/p&gt;

&lt;p&gt;Discovered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In my Brewery class, I had an instance method called "self.find_or_create_by_state"
This method was creating objects from each nested hash and keeping the list. Basically creating a list and adding more created lists to the initial list. &lt;/li&gt;
&lt;/ul&gt;




&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                      SOLUTION!!!!!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The solution was so simple. Clear the original list before creating a new list. &lt;/p&gt;

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

&lt;p&gt;Lesson Learnt&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use binding.pry for each line of code to understand what the terminal is printing and how the code is printing that line. &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ruby</category>
      <category>gem</category>
    </item>
    <item>
      <title>Why I'm studying Software Engineering</title>
      <dc:creator>lycho33</dc:creator>
      <pubDate>Sat, 13 Feb 2021 17:58:37 +0000</pubDate>
      <link>https://dev.to/lycho33/why-i-m-studying-software-engineering-365</link>
      <guid>https://dev.to/lycho33/why-i-m-studying-software-engineering-365</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RAnv0OXY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1ncr3s86l4e6xhbiehgu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RAnv0OXY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1ncr3s86l4e6xhbiehgu.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the start the Pandemic changed everything. I had just graduated from grad school and was looking forward to finding a job right after. There was no doubt in my mind that this was the next step but there was always a fear lurking in the back of my mind that I wasn't ready or qualified to work. What the Pandemic did in the beginning was amplify my worries and shrivel my confidence in myself. With constant rejections and no direction, I began drown in my fears and no matter how much comfort others gave me, it was blocked by the negativity. &lt;/p&gt;

&lt;p&gt;After that phase, I stopped to rethink my goals. First, I had to remind myself that I went to grad school because I wanted to be in education. Second, I had review what interests I leaned towards by the end of graduation. Third, I had to look at why and for whom I wanted to help. &lt;/p&gt;

&lt;p&gt;During the Pandemic, I began to tutor English to kids residing in Asia. From an underprivileged background, I could feel that they had vigor and motivation to study online. More importantly, they knew how important English was to their future. Working with them required me to expand my creativity in sustaining their motivation and help me learn the real beauty of learning online. By creating a hybrid of online and analogue pedagogy, I could see the students motivation never faltering. It was surprisingly personable experience that was almost as real. Soon my thought lingered to the questions:&lt;/p&gt;

&lt;p&gt;Could these virtual lessons help them in the real world? How? And do they leave tangible impact on the student?&lt;/p&gt;

&lt;p&gt;These were all questions that begun to re-spark my passion. &lt;/p&gt;

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

&lt;p&gt;It was from tutoring that I could solidify that I want to join the Education Technology field. So what's my goal? I'd like to enhance the online learning experience. My experience showed me that online learning has the potential to connect unexpected people together and even have a meaningful experience. &lt;/p&gt;

&lt;p&gt;Why software engineering?&lt;/p&gt;

&lt;p&gt;For the short-term goal, I want to create websites that enhance my student's learning experience. But for the long term, I would like to continue discovering how web design can cater more towards the human experience in online learning and transfer the virtual experience into the real world.  &lt;/p&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
