<?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: Bessy Clarke</title>
    <description>The latest articles on DEV Community by Bessy Clarke (@bclarke329).</description>
    <link>https://dev.to/bclarke329</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F477024%2Fed2a291a-5a92-4f62-ab34-bb0d6881f06b.jpeg</url>
      <title>DEV Community: Bessy Clarke</title>
      <link>https://dev.to/bclarke329</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bclarke329"/>
    <language>en</language>
    <item>
      <title>JavaScript: Iterator CheatSheet</title>
      <dc:creator>Bessy Clarke</dc:creator>
      <pubDate>Fri, 08 Oct 2021 06:20:56 +0000</pubDate>
      <link>https://dev.to/bclarke329/javascript-iterator-cheatsheet-2pgn</link>
      <guid>https://dev.to/bclarke329/javascript-iterator-cheatsheet-2pgn</guid>
      <description>&lt;p&gt;I recently did a mock technical interview. I chose to do it on React. I spent the entire week practicing writing components, setting local state, and passing props. The first 10 minutes or so was the 'non-technical' portion of the interview. My interviewer used this time to ask me basic questions on JavaScript. I should have seen this coming, considering React is a JavaScript framework, but I didn't study up on my basics and found myself a bit unprepared. &lt;/p&gt;

&lt;p&gt;One of the questions she asked me was, "What is the difference between &lt;code&gt;.forEach&lt;/code&gt; and &lt;code&gt;.map&lt;/code&gt;?" I didn't know the answer and just gave the first thought that came into my head as an answer. It wasn't quite right, but it also wasn't totally wrong. Either way, I decided to make myself a JavaScript iterator cheatsheet. In my coding bootcamp, they always mentioned not trying to memorize code, but iterators seem like a good thing to have memorized. Knowing off the top of your head which iterator to use when coding will save you so much time. I know there are hundreds of iterator cheat sheets on google, but what better way to study and make sure you understand exactly what you're talking about than writing a blog? This blog is meant for personal use, but if it helps you too, Awesome!&lt;/p&gt;

&lt;p&gt;Let's just dive right in!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array.forEach()&lt;/strong&gt;&lt;br&gt;
This iterator calls a function once for every element in an array &lt;/p&gt;

&lt;p&gt;The argument for this method is a callback function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let students = ['Bessy', 'Tom', 'Adam', 'Ben', 'Martha']

students.forEach(function(students) {
  console.log(`${students} is a senior in college`)
})

=&amp;gt; Bessy is a senior in college
   Tom is a senior in college
   Adam is a senior in college
   Ben is a senior in college
   Martha is a senior in college
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;forEach()&lt;/code&gt; returns &lt;strong&gt;undefined&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;You want to use &lt;code&gt;forEach()&lt;/code&gt; the least. While it will iterate through your array, because it doesn't return anything, you can't pass the return value to another function for use. It can also be hard for another programmer to understand what exactly you're trying to do with this method. If you feel like you need to use &lt;code&gt;.forEach()&lt;/code&gt;, DON'T,  you're better off using &lt;code&gt;.map()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array.map()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just like &lt;code&gt;forEach()&lt;/code&gt;, &lt;code&gt;.map()&lt;/code&gt;iterates over all elements and allows you to perform some operation to each element in that array and changing them into something else. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;.map()&lt;/code&gt; returns a new array, leaving the original array unchanged. &lt;/p&gt;

&lt;p&gt;We use &lt;code&gt;.map()&lt;/code&gt; when we want to perform an action on each element in the the array and collect the results into a new array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let numbers = [2,4,6,8,10]
  let odds = numbers.map(x =&amp;gt; x + 1)
=&amp;gt; numbers: [2,4,6,8,10]
=&amp;gt; odds: [3,5,7,9,11]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, I use &lt;code&gt;.map()&lt;/code&gt; to add 1 to each element in the number array. I assign the method to a variable called "odds" to give the returned array something to reference when it's time to call it. If we call the numbers array, we can see the original array remains unchanged. When we call the odds array, we can see this new array that has changed by the &lt;code&gt;.map()&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array.find()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.find()&lt;/code&gt; returns the first element that meets a specified condition. It's good to note that you could have multiple matches, but it will only return the first one that matches the condition. If no match is found, it will return &lt;strong&gt;undefined&lt;/strong&gt;. Only use it when you want to isolate a specific result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let dogNames = ["Suki", "Lumi", "Mia", "Sophie", "Coco"]

let result = dogNames.find(name =&amp;gt; name.startsWith("S"))

=&amp;gt; "Suki"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we have an array dog names, but want to find one of the names that start with "S", "Suki" will be the first name returned, because it's the first name that appears in the array that satisfies the condition set in the callback function. &lt;/p&gt;

&lt;p&gt;We can even add a second condition with the Logical And (&amp;amp;&amp;amp;) operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dogNames.find(name =&amp;gt; name.startsWith("S") &amp;amp;&amp;amp; name.length &amp;gt; 4)

=&amp;gt; "Sophie"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Array.filter()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.filter()&lt;/code&gt; goes through each element in an array and keeps any element that meets the defined condition. The callback function needs to return either true or false. If it returns true, the new array keeps that element and filters out the ones that return false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let dogNames = ["Suki", "Lumi", "Mia", "Sophie", "Coco"]

let sNames = dogNames.filter(name =&amp;gt; name.startsWith("S"))
=&amp;gt; ["Suki", "Sophie"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we had that same array of dog names, but wanted to find all of the names that start with the letter "S". &lt;code&gt;filter()&lt;/code&gt; would make a new array, leaving us with just those names,&lt;br&gt;
while leaving the original array unchanged. &lt;/p&gt;

&lt;p&gt;This is just a basic rundown of some commonly used JavaScript iterators. Being able to manipulate, sort, or find specific data in arrays is something you'll do often, so it's important to make sure you know what each of these iterators does, how they're used, and what they return. Hope this helps! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fetching &amp; Fetching </title>
      <dc:creator>Bessy Clarke</dc:creator>
      <pubDate>Thu, 26 Aug 2021 04:57:43 +0000</pubDate>
      <link>https://dev.to/bclarke329/fetching-fetching-1epk</link>
      <guid>https://dev.to/bclarke329/fetching-fetching-1epk</guid>
      <description>&lt;p&gt;After a change of pace in my Flatiron program, I'm finally nearing the end of the Javascript module. We were tasked with building a single-page application, using HTML, CSS, and plain old Javascript on the frontend with a Ruby On Rails backend. The inspiration behind my project was my newfound obsession with Dungeons &amp;amp; Dragons. I play weekly and I've really enjoyed getting into character and expanding who my character is throughout our sessions. I play with a group of five people. When we were in the early stages of choosing our characters, we got together and were told to pick characters that complemented each other's skill set. So, you definitely want someone on your team who maybe is a skilled fighter, but you'd also want someone who can use magic to heal other players after intense fights. &lt;/p&gt;

&lt;p&gt;I built a Dungeons &amp;amp; Dragons character creator that lets you create parties and add characters to a party and see them laid out. I used the handy dandy DnD API to fetch their data and use it in my project. I made multiple fetch requests to different endpoints. I then used this fetched data to render information to the DOM while leaving the HTML file pretty barebones. &lt;/p&gt;

&lt;p&gt;Fetch is a pretty cool Javascript function and it can be used in a plethora of ways to make very useful apps. There are so many great APIs available and being able to use fetch opens their data to developers for use in applications. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Fetch()&lt;/code&gt; is an AJAX technique that has been abstracted into a easy to use function. AJAX stands for Asynchronous JavaScript And XML. AJAX uses a XMLHttpRequest object to communicate with servers. It allows us to render HTML and CSS, while giving us just enough time to render Javascript quickly and behind the scenes without the user growing inpatient. &lt;/p&gt;

&lt;p&gt;In my project, I use several fetch requests to the DnD API to gather the names of character races, classes, alignments, and weapons.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    static getSpecies() {
        fetch('https://www.dnd5eapi.co/api/races')
        .then(response =&amp;gt; response.json())
        .then(data =&amp;gt; {
            // console.log(data)
            this.addSpeciesToDrop(data)
            // debugger
        })
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we use &lt;code&gt;fetch()&lt;/code&gt; we pass in the URL of the data we're trying to retrieve. What comes back in this round of the method is called a &lt;code&gt;Promise&lt;/code&gt;. This &lt;code&gt;Promise&lt;/code&gt; does not send the actual data. Rather it returns the state of that data. Promises can have three states: pending, fulfilled, rejected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [[PromiseState]]: "fulfilled"
    [[PromiseResult]]: Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we have our fulfilled promise, we chain on a &lt;code&gt;.then()&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  fetch('https://www.dnd5eapi.co/api/races')
  .then(response =&amp;gt; response.json())
  Promise {&amp;lt;pending&amp;gt;}
 __proto__: Promise
 [[PromiseState]]: "fulfilled"
 [[PromiseResult]]: Object
 count: 9
 results: (9) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, 
 {…}, {…}]
__proto__: Object

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

&lt;/div&gt;



&lt;p&gt;This first &lt;code&gt;.then()&lt;/code&gt; method starts to give us data that we can start to look through. We can see that it gives us a count of the data we're working with. In my example, I get an array of objects. Each object is made up of an index, a name for the data, and the URL of where it's located in the API. I also take the response received from the &lt;code&gt;.then()&lt;/code&gt; call and turn it into JSON (Javascript Object Notation), which tells JavaScript to render this data into nested objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;results: Array(9)
0: {index: "dragonborn", name: "Dragonborn", url: "/api/races/dragonborn"}
1: {index: "dwarf", name: "Dwarf", url: "/api/races/dwarf"}
2: {index: "elf", name: "Elf", url: "/api/races/elf"}
3: {index: "gnome", name: "Gnome", url: "/api/races/gnome"}
4: {index: "half-elf", name: "Half-Elf", url: "/api/races/half-elf"}
5: {index: "half-orc", name: "Half-Orc", url: "/api/races/half-orc"}
6: {index: "halfling", name: "Halfling", url: "/api/races/halfling"}
7: {index: "human", name: "Human", url: "/api/races/human"}
8: {index: "tiefling", name: "Tiefling", url: "/ap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then chain one more &lt;code&gt;.then()&lt;/code&gt; call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  static getSpecies() {
        fetch('https://www.dnd5eapi.co/api/races')
        .then(response =&amp;gt; response.json())
        .then(data =&amp;gt; {
            this.addSpeciesToDrop(data)
        })
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can finally start to write code that lets us use this data in the third &lt;code&gt;.then()&lt;/code&gt; call. In the above example, I use an arrow function to call another function. I wrote a separate method that takes in the data sent back from the fetch request as an argument and use this data to append the names of the species into a dropdown menu. And just like that, we can gather data from an external source and use it to populate our own personal applications.&lt;/p&gt;

&lt;p&gt;Along with letting us use data from external sources in our apps, &lt;code&gt;fetch()&lt;/code&gt; also lets us use this same method, with some variation, to send data back to our APIS. I created an API to hold my information on parties and their corresponding characters. So, to save those characters into my database, we need to let the fetch method know that we're sending a "POST" request. By default, fetch uses the HTTP verb "GET".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let character = {
                name: name,
                race: race,
                character_class: characterClass, 
                alignment: alignment,
                primary_weapon: primaryWeapon, 
                secondary_weapon: secondaryWeapon,
                // party_id: partyId
            }
            fetch("http://127.0.0.1:3000/characters", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                    "Accept": "application/json"
                  },
                body: JSON.stringify(character)
            })
            .then(resp =&amp;gt; resp.json())  
            .then(character =&amp;gt; {
                alert("Character has been created!") 
                let char = new Character(character.id, character.name, character.race, character.character_class, character.alignment, character.primary_weapon, character.secondary_weapon)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I created an object that holds the information I'm using to instantiate my character. In my case, I'm instantiating each character with a name, race, character class, alignment, and two weapons. We include a "Header", which tells the method two things. The format the content we're sending back is in, and what data form to accept. Headers can be used to include API authentication keys, that is if your API has restrictions on how it's used, or it can even include user data for cookies. I then use that object set before the fetch method to pass it into the body. Here, I turn this object into JSON so that javascript can properly read and render this data. After chaining on our two &lt;code&gt;.then()&lt;/code&gt; calls, I instantiate my character object and let the user know that the character creation was successful!&lt;/p&gt;

&lt;p&gt;Fetch is a great AJAX tool that has simplified the way we can talk to servers and retrieve desired information from them. I initially had a little trouble with fetch, specifically, working with the data, but by the end of this project, I'm looking forward to working with more APIs to build different projects! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>What To Expect If You're Planning On Attending A Coding Bootcamp </title>
      <dc:creator>Bessy Clarke</dc:creator>
      <pubDate>Thu, 12 Aug 2021 06:02:45 +0000</pubDate>
      <link>https://dev.to/bclarke329/what-to-expect-if-you-re-planning-on-attending-a-coding-bootcamp-3cdd</link>
      <guid>https://dev.to/bclarke329/what-to-expect-if-you-re-planning-on-attending-a-coding-bootcamp-3cdd</guid>
      <description>&lt;p&gt;I just finished a coding bootcamp and I wanted to share some unsolicited advice and tips on what to do to prepare, succeed, and managing your expectations after the program is over. This advice is mostly aimed at people who have never written a line of code in their life, or the people who never even saw themselves trying to learn how to code. &lt;/p&gt;

&lt;h2&gt;
  
  
  Preparing for your bootcamp
&lt;/h2&gt;

&lt;p&gt;Before I applied to my bootcamp and got accepted, I spent six months teaching myself how to code--HTML. While HTML is definitely important and has its place, I would recommend you start learning some actual programming. Most bootcamps teach you Javascript, so I would definitely start there. I wish I had used that time prior to applying learning JS. Javascript is most people's first programming language. Learning Javascript will give you a real idea on whether you'll like coding in general and introduces you to concepts that are pretty universal in whatever language you want to learn down the line. Concepts such as, variables, iteration, and working with data structures are all so important and being comfortable with all of those things will set you up for success when it comes time to do it in your bootcamp. &lt;/p&gt;

&lt;p&gt;If you're seriously considering learning how to code through the bootcamp route, I'd also get in the habit of coding daily as soon as you can. Start small with the aim of it becoming a sustainable habit. Once you get to your bootcamp, especially if you plan on doing it full-time, you'll be learning and coding for eight hours a day sometimes. My particular bootcamp suggested putting in a minimum of 40 hours a week to stay on track with the curriculum. I went from coding an hour or two a few times a week to having to code over six hours daily. I quickly became burnt out cause it was such a huge adjustment. So, start early and small, but increase your time as you go and make it into a habit. Block off time in your schedule, make a comfortable work space, and just experiment with what works for you. &lt;/p&gt;

&lt;h2&gt;
  
  
  Tips for being successful in your bootcamp
&lt;/h2&gt;

&lt;p&gt;Coding bootcamps, especially online programs emphasize the importance of community. Learning online can feel very lonely. So they recommend befriending people in your cohort and reaching out to them when you need help. I 1000000% recommend you do this. I was originally very shy and didn't see myself wanting to reach out to people, especially ones that I didn't know, but I can't tell you how many times my cohort mates were around to keep me going. I basically had a breakdown while building my first project, I was so ready to quit. I even read through my contract to see if I'd get my money back if I left the program right there and then. Long story short, one of the students in my pod reached out, worked with me all weekend, and got me back on track with my project. To this day, I think I would have quit if it wasn't for this person. I had another pod mate reach out to meet weekly and check how I was doing. I connected with another student and he quickly became the person I'd reach out to if I needed help on labs or just needed help with concepts. Basically, make as many friends as you can, because you're definitely going to need them at some point. &lt;/p&gt;

&lt;p&gt;Prepare to be a beginner. That is something I didn't do enough and I wish I had been kinder to myself along the way. I always thought the teachers were expecting you to be an expert coder right off the bat, and that is not the case. It's okay if your projects aren't great at the beginning, or even if they're not that great at the end. Everyone learns differently and even if you've coded for 5 months straight, you are still a beginner! Rome wasn't built in a day. &lt;/p&gt;

&lt;p&gt;One last thing, do not compare yourself to others. Some people learn quickly, others have a science background, or just a more complementing background to coding that allows them to pick up the basics faster. I spent the entire time feeling like everyone was smarter than I am and building really amazing things, while my projects never lived up. Truth is, you'll only think yours is bad because you built it. Others will see yours as amazing and feel the same way. Comparison is the thief of joy. Be proud of what you build and think of how far you've come. I didn't know how to code at all in the beginning and now I have five working projects under my belt. It's worth being proud of. This goes back to managing your expectations. A coding bootcamp isn't going to make you an all-star coder, but it will set you up with the right foundation to keep learning and growing as a coder. &lt;/p&gt;

&lt;h2&gt;
  
  
  What To Expect After The Program
&lt;/h2&gt;

&lt;p&gt;You're equipped with a new skill and ready to take on the job market, now what? It's important to manage your expectations on what comes after. A lot of bootcamps make these very convincing claims, stating that you can find a job within six months of graduating. While it may be true for some people, it isn't true for all. That's not to say you can't or won't find one, but to prepare you for the reality. &lt;/p&gt;

&lt;p&gt;I was in two different cohorts during my bootcamp. I was originally doing the full-time pace and switched to the part-time. So, my full-time cohort graduated before me and I was able to keep up with a few of them and hear what their experience was after the program. I was also lucky enough to meet a few alumni who were very honest about their experience after the program was over. &lt;/p&gt;

&lt;p&gt;I want to preface this by saying, I have spoken or heard of a lot of people who like me, started with no coding experience, and went off to get great jobs afterwards. The program works, but I think it's important to be prepared about what the search can be like. I also want to say that I can't speak on my own experience, as I have just finished and have not declared my job search, or even passed my assessment (at the point of this being written). &lt;/p&gt;

&lt;p&gt;A lot of the students in my full-time cohort got jobs very quickly! I know at least four students that got a job within 2-3 months of graduating from the program, which is really awesome! While that is definitely fast, what you don't hear is the amount of applications they had to put in to land that job, or the amount of rejections they had to receive beforehand. One of my peers shared with me that prior to landing his job, he had put in 25 applications and was turned down by mostly all of them, and he interviewed for three. I say this because I can imagine being rejected so many times to be demoralizing for myself, so it's important to go into the process  just knowing what to expect. You'll be told "no" a lot, but don't take those rejections to heart.&lt;/p&gt;

&lt;p&gt;While some did get jobs within the six month period, others had to deal with a much longer job search. I know some people who were unemployed for closer to seven months and some even went past the year mark still searching for one. The ladder stated in a LinkedIn post that he eventually ended up putting in close to 1000 applications before finding a job. Moral of the story is, you may be lucky and find a job quickly, or you may have to deal with a slightly longer job search. I say this to prepare you. If breaking into tech is something you really want to do, the key is being patient and remaining positive. &lt;/p&gt;

&lt;p&gt;One more thing, keep learning!! Finishing the program does not mean you know everything there is to learn about coding. Your bootcamp just set you up with a good foundation on how to learn and continue to do so on your own. Stay connected with your cohort peers. Reach out when you need help or just want to go over concepts to keep them fresh. &lt;/p&gt;

&lt;h2&gt;
  
  
  Recap
&lt;/h2&gt;

&lt;p&gt;There are many ways to approach learning how to code. The bootcamp route is just one way. While this route can be a little higher in costs, it does give you a set structure to follow, and can help keep you accountable to your goals. Since I was such a beginner, I thought this path was the best one for me. It also connected me with people all over the country that went above and beyond to help me stay on track. I would probably do it again if I had to make the choice all over. I am still very new at coding, but I don't believe that I could have built the things I did without the path that my bootcamp set up for me. I know a lot of beginners are often stuck in what a lot of people call "tutorial hell". So, I appreciate being given a solid path that challenged me in a lot of ways. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Deeper Look Into Active Record Associations and Their Methods</title>
      <dc:creator>Bessy Clarke</dc:creator>
      <pubDate>Thu, 03 Dec 2020 21:59:16 +0000</pubDate>
      <link>https://dev.to/bclarke329/a-deeper-view-into-active-record-associations-and-their-methods-2p1n</link>
      <guid>https://dev.to/bclarke329/a-deeper-view-into-active-record-associations-and-their-methods-2p1n</guid>
      <description>&lt;p&gt;In my last post, I talked about my second project for Flatiron's software engineering course. I built a web application that allows a user to track the condition of their skin and log any comments in regard to how it feels on any particular day. Using SQLite as a database, the user is also able to view any past logs and make any changes if necessary. I glossed over it in my previous post, but I wanted to take a deeper look into using Active Record. Specifically, how we can establish relationships using Active Record between our models and the various new methods that we gain from it. &lt;/p&gt;

&lt;p&gt;Active Record gives us a few different options with the type of relationship we establish between our models.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   has_one
   has_many
   has_many :through
   has_one :through
   has_and_belongs_to_many
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my case, I had a model and a table for a user, and another set for my logs. I used a one to many relationship between the two. A user &lt;code&gt;has_many&lt;/code&gt; logs, while each log &lt;code&gt;belongs_to&lt;/code&gt; a designated user. To set up the relationship, I started by adding a &lt;code&gt;user_id&lt;/code&gt; column in my logs table, because the logs belong to a user, we set the foreign key in the table of objects that belongs to another model. I then just had to add Active Record's macros into the models.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ActiveRecord::Base 
      has_many :logs
end

class Log &amp;lt; ActiveRecord::Base
      belongs_to :user
end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And just like that, the association is set between the user and the logs they create!  Active Record also gives us a lot of very cool methods to use with our models. They vary depending on what association is used. Since I used the belongs_to/has_many association in my project, I'm going to elaborate a little more on the methods we gain from the use of these macros. &lt;/p&gt;

&lt;p&gt;The belongs_to association creates a 1-1 relationship between two different models. So, each log can only have one user or one creator. This association gives us six methods that we can use with our models.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   association
   association=(associate)
   build_association(attributes = {})
   create_association(attributes = {})
   create_association!(attributes = {})
   reload_association
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'll demonstrate a few of these methods through the context of my project and it's models. In these methods, just replace the word "association for the model passed into the argument of &lt;code&gt;belongs_to&lt;/code&gt;. In my case, a 'log' &lt;code&gt;belongs_to :user&lt;/code&gt;. Each instance of the 'log' model will have access to these new methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   user
   user=
   build_user
   create_user
   create_user!
   reload_user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;association&lt;/code&gt; method just returns the associated object, if none can be found, it just returns nil. If the object associated has already been retrieved from the database, we can use another one of our handy dandy methods to override this behavior, by calling &lt;code&gt;reload_user&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, we have the &lt;code&gt;association=(associate)&lt;/code&gt; method. In my case, it would look like this &lt;code&gt;user=(log)&lt;/code&gt;. Here we can assign an object to be associated with this other. This basically means, we take the primary key from the associated object and set the other object's foreign key to the same number. So, if I had a log, that somehow wasn't associated to a particular user at creation, I could go in and manually do it with this method. &lt;/p&gt;

&lt;p&gt;Another, important one to know is the &lt;code&gt;build_association(attributes = {})&lt;/code&gt;. It would look like this in the case of my project, `&lt;a class="mentioned-user" href="https://dev.to/log"&gt;@log&lt;/a&gt;
.build_user(:name =&amp;gt; "Bessy", :email =&amp;gt; "&lt;a href="mailto:test@email.com"&gt;test@email.com&lt;/a&gt;"). This method basically allows us to create a new instance of a user that has the attributes I passed in. So, to recap, I basically created a new user that has a name and an email, all through that method alone. It's important to note that if you use this method, your object will NOT be saved. &lt;/p&gt;

&lt;p&gt;To create an instance and then save it, we can use the &lt;code&gt;create_association(attributes = {})&lt;/code&gt;. Following the same format as previously, we simply use &lt;code&gt;@log.create_user(:name =&amp;gt; "Bessy", :email =&amp;gt; "test@email.com")&lt;/code&gt;. It has to pass all of the validations specified by the associated model before it can be saved. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;create_association!(attributes = {})&lt;/code&gt; or  &lt;code&gt;@log.create_user!(:name =&amp;gt; "Bessy", :email =&amp;gt; "test@email.com")&lt;/code&gt; does virtually the same as the create_association method above, but the addition of the bang operator raises an error if the record is not valid. &lt;/p&gt;

&lt;p&gt;As I mentioned previously, the methods gained from Active Record, vary on which associative macro you used. The &lt;code&gt;has_many&lt;/code&gt; association comes with its own methods that we'll explore as well. The &lt;code&gt;has_many&lt;/code&gt; association, creates a one to many relationship. One object can have many things. We gain 17 new methods related to this association!!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
collection&lt;br&gt;
collection&amp;lt;&amp;lt;(object, ...)&lt;br&gt;
collection.delete(object, ...)&lt;br&gt;
collection.destroy(object, ...)&lt;br&gt;
collection=(objects)&lt;br&gt;
collection_singular_ids&lt;br&gt;
collection_singular_ids=(ids)&lt;br&gt;
collection.clear&lt;br&gt;
collection.empty?&lt;br&gt;
collection.size&lt;br&gt;
collection.find(...)&lt;br&gt;
collection.where(...)&lt;br&gt;
collection.exists?(...)&lt;br&gt;
collection.build(attributes = {}, ...)&lt;br&gt;
collection.create(attributes = {})&lt;br&gt;
collection.create!(attributes = {})&lt;br&gt;
collection.reload&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
I obviously can't cover all seventeen methods, but I'll recap on the more common ones used. Like before, just replace &lt;code&gt;collection&lt;/code&gt; with the symbol passed as the argument to the &lt;code&gt;has_many&lt;/code&gt; macro. So because I used, &lt;code&gt;has_many :logs&lt;/code&gt;, all instances of the User model will gain these methods. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;collection&lt;/code&gt; method here, &lt;code&gt;@user.logs&lt;/code&gt; will return all of the associated objects. If there are none, it returns an empty Relation.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;collection &amp;lt;&amp;lt;(object,..)&lt;/code&gt; would add one or more objects to the collection by setting their foreign keys to the primary key of the calling model. So, if I had a user with a primary key of 25, I could then use the shovel operator to add new instances of logs and set their foreign key to 25, to associate those logs to user number 25. This method could look something like this &lt;code&gt;user.logs &amp;lt;&amp;lt; new_log&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Similar to some of the methods gained from the &lt;code&gt;belongs_to&lt;/code&gt; association, the &lt;code&gt;has_many&lt;/code&gt; also gives us &lt;code&gt;collection.build&lt;/code&gt; and &lt;code&gt;collection.create&lt;/code&gt;. There are a few differences to note though. With the &lt;code&gt;has_many&lt;/code&gt; association, these methods return a single array, or an array of new objects corresponding to the associated type. &lt;/p&gt;

&lt;p&gt;If we used, `@user.logs.build(:current_condition =&amp;gt; "normal", :new_products =&amp;gt; true, :comments =&amp;gt; "Everything is normal!") The log will be instantiated with the attributes I passed into the build method, and the link through the key will be created, but it will NOT be saved!&lt;/p&gt;

&lt;p&gt;On the other hand, if we used &lt;code&gt;@user.logs.create(:current_condition =&amp;gt; "normal", :new_products =&amp;gt; true, :comments =&amp;gt; "Everything is normal!")&lt;/code&gt;, we can just save that new instance of a log after it passes the validations. &lt;/p&gt;

&lt;p&gt;There are so many methods that Active Record gives us with the use of associations. I am barely scratching the surface here. If you're starting a rails project, I recommend you check out the documentation that goes along with it. Feel free to drop some comments, tips, or any questions. :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title> Sinatra knows this ditty. </title>
      <dc:creator>Bessy Clarke</dc:creator>
      <pubDate>Tue, 24 Nov 2020 03:19:05 +0000</pubDate>
      <link>https://dev.to/bclarke329/sinatra-knows-this-ditty-1k2a</link>
      <guid>https://dev.to/bclarke329/sinatra-knows-this-ditty-1k2a</guid>
      <description>&lt;p&gt;Two projects down, three more to go! My time in this program is flying by! For this project, we were asked to create a web app using Sinatra. After working in the terminal during the first phase of Flatiron's program, I was looking forward to working in the browser. Our app should let users signup, login, and log out. It should also take in user data and save it into a database using SQLite, and using the RESTful routes, create an app that applies the principles of CRUD (create, read, update, delete). &lt;/p&gt;

&lt;p&gt;I decided to make a simple web app that lets users keep track of how their skin feels, what skincare products they're using, and leave themselves a quick log with any concerns, general comments, or just words of encouragement. I was inspired by my own skin woes and felt like I could have used an app like this when I started my course of treatment with my dermatologist. I called my site, DermaLog.  &lt;/p&gt;

&lt;p&gt;I originally planned to build the structure of my project from scratch, but I ran into some issues connecting my database early on. Enter the Corneal gem. This gem created my project structure and connected my application to a database instantly. I spent a lot of time attempting to do it from scratch and this gem cut that time down to a literal thirty seconds! I will now and forevermore use this gem for any future Sinatra projects. &lt;/p&gt;

&lt;p&gt;To organize the structure of the application, I used the Model-View-Controller pattern, which the corneal gem built out instantly. This allowed me to keep to the separation of concerns and make sure that all my files pertained to one task. My model folder holds my classes for a user and another for a "log". This is where the classes that create my instances are stored. I needed to create a new instance of a user every time someone signed up and an instance of a log, every time the user wanted to create one. The views folder holds all the files that correspond to the different in-browser views my user will interact with. It is where all the HTML and CSS live. The controllers hold all the logic behind my routes. They essentially control the flow of my app.&lt;/p&gt;

&lt;p&gt;To start I created two databases. One to store login credentials for my users and another to store my data being submitted via my log form. I associated both tables with one another by using activerecord's associations. Active Record comes with macros that make associating both our tables so simple. By inserting the &lt;code&gt;belongs_to&lt;/code&gt; and &lt;code&gt;has_many&lt;/code&gt; macros, and creating a column for a &lt;code&gt;user_id&lt;/code&gt; in my 'logs' database, I was able to associate each log to a user and have that data belong to the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ActiveRecord::Base
    has_secure_password

    validates_presence_of :name, :email, :password
    validates :email, uniqueness: true 

    has_many :logs
end 

class Log &amp;lt; ActiveRecord::Base
    belongs_to :user
end  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Active Record also comes with macros that let me validate the email and password my users enter. It prevents my users from creating multiple accounts associated to the same email, or ensures that all users input the correct login details. Look at me! I built my first working login!   &lt;/p&gt;

&lt;p&gt;As mentioned previously, one of the requirements was to use the RESTful routes convention. Learning this really improved my understanding of how the internet works and how pages in an application are connected to one another. I feel like I can better picture how a site like Tumblr, or even Dev can be built. Obviously, they have far more complexity than what I've built, but I can see how these routes form the bones of a much larger application. I can even see how with the basic structure I've already built, I can add on to turn DermaLog into an application with a lot more functionality and features. Alas, a week is too little time and I do feel like most of my learning happens when I tackle my projects. The program is moving fast and as much as I would like to add way more features now, I've built a minimum viable product that works. I am definitely looking forward to adding to this one at the end of the program. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building My First CLI</title>
      <dc:creator>Bessy Clarke</dc:creator>
      <pubDate>Tue, 27 Oct 2020 01:40:29 +0000</pubDate>
      <link>https://dev.to/bclarke329/building-my-first-cli-42pg</link>
      <guid>https://dev.to/bclarke329/building-my-first-cli-42pg</guid>
      <description>&lt;p&gt;I've made it to the end of my first phase at Flatiron School. To mark the end of the phase, I had to build my first application. The assignment was to scrap a website using Ruby and then use the data to build a CLI. I originally envisioned a much more snazzy app, but in the end, I kept it simple and to the point. &lt;/p&gt;

&lt;p&gt;I wanted to build an app that displayed all the UNESCO Heritage sites across the US. The idea was for the user to interact with the CLI by displaying the site names, having the user select their chosen one, and then return a small chunk of information about each one. The whole process was a big learning curve, and while I did not get to implement some of the aspects of my original plan, I'm still very proud of what I made and hope to be able to gain more skills to make it better. &lt;/p&gt;

&lt;p&gt;For starters, prior to Flatiron, I had never interacted with a terminal or even knew what a CLI was, so to be able to make something after one month is pretty exciting. Outside of actually coding the project, I learned how to connect and upload code to Github. I learned how to navigate the terminal and run files, which I had never done outside of the lessons and labs we are given. Armed with this knowledge, I am quite excited to build more things and working in the terminal made me feel like a hacker!&lt;/p&gt;

&lt;p&gt;Building the project presented its own challenges. Leading up to the project, I was a little unclear about the principles of object-oriented programming. The idea of instantiating an object felt a bit abstract and it remained so throughout my project week. It wasn't until the Saturday prior to turning in the project that it finally clicked. Every time the scraper was called, it created a new instance of site, which then allowed Ruby to make each site an actual object in its memory. Each site was instantiated with a site name, a category, information, and the URL to the second level scrape. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  `Site.new(site_name, category, info, and URL).`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The actual act of scraping a website also caused a lot of grief. It was so frustrating to choose the correct CSS selectors that would return the precise elements that I needed. Nokogiri made the process of scraping a little simpler though. I used Nokogiri to return the HTML elements on the page into a rendered format that Ruby could then interpret. Although I will say that I expected the process to be like an actual hot Nokogiri saw through butter, and less like a blunt knife going through a tomato. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;first_url = "https://whc.unesco.org/en/statesparties/us"&lt;br&gt;
        html = open(first_url)&lt;br&gt;
        parsed_elements = Nokogiri::HTML(html)&lt;br&gt;
        unesco_cultural = parsed_elements.css("div.box li.cultural")&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The biggest challenge was trying to find a website that was scrappable(is that even a word?) for both levels, which was the project requirement. Despite how frustrating scraping could be, I am thinking of finding more websites to scrape to hopefully build another CLI app. It ended up being great practice and also exposed the gaps in my knowledge, forcing me to review and research to complete the project. &lt;/p&gt;

&lt;p&gt;Before wrapping up, I have to give a huge nod to the Pry Ruby gem. I didn't use it much prior to the project, but now I am wondering how I made it through my labs without it. It was so easy to inject a "binding.pry" into my methods and figure out exactly what was going wrong. Having the ability to check each and every variable and confirming what was being returned or passed into them made the debugging a lot less of a headache. &lt;/p&gt;

&lt;p&gt;Completing this project makes this journey all the more real. I am on my way to becoming a coder, and while I didn't build something out of this world, I am very much looking forward to revisiting this project and seeing how much I grow as a coder over the new few months.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Going from Completely Clueless to Savvy Software Engineer 
</title>
      <dc:creator>Bessy Clarke</dc:creator>
      <pubDate>Fri, 09 Oct 2020 16:19:41 +0000</pubDate>
      <link>https://dev.to/bclarke329/going-from-completely-clueless-to-savvy-software-engineer-4bk9</link>
      <guid>https://dev.to/bclarke329/going-from-completely-clueless-to-savvy-software-engineer-4bk9</guid>
      <description>&lt;p&gt;How does a person go from barely being able to share an old memory on Facebook to becoming an aspiring software engineer? I’d like to tell you that I’m exaggerating my Facebook sharing skills but it’s painfully true. I meant to share an old photo with friends. “Remember this?!” I captioned with a couple of emojis only to have my friend say, “I don’t see anything. You didn’t post anything!”.  We had a good laugh that day. My friends couldn’t help but mock my grandma like Facebook skills. We had another laugh when it popped up on my memories the following year. Writing about it now, it still cracks me up. I was never a “techy” person. My husband even dubbed me the laptop killer because I ended up needing a new one every year during my undergrad. Before starting my coding journey, I had no clue what HTML, CSS, or even JavaScript were. I can’t help but smile when I think of how far I’ve come in the last year. &lt;/p&gt;

&lt;p&gt;See, I sort of fell into coding. I never saw myself as a coder. I never even imagined a career in tech could be possible for me. It wasn’t until I met my friend, Katie, that I started to see how feasible it was— even for someone as clueless as me. I remember going to her house to discuss her career in tech. She mentioned coding and I, sort of,  laughed it off. She insisted that if I was serious about wanting to get into tech, I should learn how to code. She threw so many random terms and tech jargon at me that evening and I was embarrassed by how little I knew! I cannot say that conversation sparked a lot of confidence but it did spark curiosity. &lt;/p&gt;

&lt;p&gt;I spent the next few weeks going through videos on Treehouse.com. I had to start at zero. I would often study for an hour or so and just give up because nothing made sense at the beginning. The more I got through the lessons, the more convinced I was that this skill was not something I’d be able to learn. Weirdly though, I kept at it. Every week I’d spend a few hours watching videos or listening to podcasts. I quickly became so inspired. Every story I heard was more inspiring than the last— people of all ages and backgrounds taking up code and loving it. Every story was different, but the recurring theme was the same. That this skill was life-changing and if I put in the time and effort, my life could change as well. &lt;/p&gt;

&lt;p&gt;That drive for change pushed me. I spent years being so uncomfortable with my job, but too afraid to pursue anything or make any real changes. However, the more time I spent on coding, the more I loved it. The joy after fixing broken code, or seeing something work exactly as expected, was unreal and that thrill kept me going. I knew that if I was serious about coding, I would need structure to keep me on track. That said I began researching coding bootcamps. I had this idea that I had to be a seriously good coder to even get into one. Naturally, it kept me from applying to any options I found. &lt;/p&gt;

&lt;p&gt;I had this idea that once I got to a certain level, I could start applying. I had this grand plan that I would give myself a year. I’d move to Denver and apply to Flatiron School’s Software Engineering program. Fast forward to March 2020, everyone’s’ lives are upended due to the COVID pandemic. During this time, I chose to throw myself into code. It was the only thing that kept the existential dread at bay and ultimately, decided to pursue their course online instead. I didn’t want to wait until COVID was over. &lt;/p&gt;

&lt;p&gt;I became determined to leave this strange period in my life better than I went into it. I started to apply to the Flatiron online bootcamp. I didn’t submit anything that day but somehow still got an email saying “DON’T FORGET TO FINISH YOUR APPLICATION”. I had no intention of applying at that moment. I wasn’t ready at all, but that’s the thing about making big life-changing decisions, no one is ever ready. If you wait to be ready, you’ll spend a lot of time waiting. &lt;/p&gt;

&lt;p&gt;In the end, I applied, scheduled my interview, and, by the following week, I was a Flatiron student! I was even offered a small scholarship! It was the first time I had ever been offered one.  I wouldn’t call myself a coder just yet, but in the year since I started to pursue coding, it has already changed my life. I am a week into the program and I feel like I am exactly where I need to be. I am excited to be on this journey. Coding feels like a superpower and I’m so eager to see where it takes me and how I can apply it to use in meaningful and ethical ways. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
