<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Dane Dawson</title>
    <description>The latest articles on Forem by Dane Dawson (@danedawson).</description>
    <link>https://forem.com/danedawson</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%2F335401%2F775aae1f-b946-4479-b18b-58364c1f54b5.png</url>
      <title>Forem: Dane Dawson</title>
      <link>https://forem.com/danedawson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/danedawson"/>
    <language>en</language>
    <item>
      <title>My experiences at coding bootcamp</title>
      <dc:creator>Dane Dawson</dc:creator>
      <pubDate>Thu, 24 Sep 2020 16:45:23 +0000</pubDate>
      <link>https://forem.com/danedawson/my-experiences-at-coding-bootcamp-4h12</link>
      <guid>https://forem.com/danedawson/my-experiences-at-coding-bootcamp-4h12</guid>
      <description>&lt;p&gt;On January 27, 2020 I started attending FlatIron, a 15 week software engineering program. It was a wild, exhausting, and crazy experience and, on May 8th, 2020, I graduated! I thought I would take a moment to talk a bit about what my experience was like for those interested in maybe attending a boot camp in the future, and at the end I wanted to give some base tips to those wanting to learn to code (formally taught or not).&lt;/p&gt;

&lt;h2&gt;
  
  
  Bootcamp? What's that?
&lt;/h2&gt;

&lt;p&gt;The school I attended was a 15 week software engineering school with a "full-stack" focus, meaning they taught Ruby and Ruby on Rails for back end server management and JavaScript and React for front end client interfacing. It was broken into the following 5 "Mods" (the taglines are my own)&lt;/p&gt;

&lt;p&gt;-Ruby - Introduction to Ruby, object oriented programming and you!&lt;br&gt;
-Ruby on Rails - More Ruby, and learning how to talk to your server through a framework. Make a website like it's the 90s!&lt;br&gt;
-JavaScript - JavaScript, love it or hate it! P.S. You will start by hating it.&lt;br&gt;
-React - Framework using JavaScript to build out and structure web design more modern and customizable. &lt;br&gt;
-Final Project -  "3 weeks" to do anything you want with the knowledge you have learned so far. Really 2 with project pitching and presentation prep.&lt;/p&gt;

&lt;p&gt;with each of the first 4 mods following the same loose schedule:&lt;/p&gt;

&lt;p&gt;-Weeks 1/2 : Introduction, education and practice of coding skills/techniques&lt;br&gt;
-Mid/End Week 2: Coding challenge to test your knowledge of the material&lt;br&gt;
-Week 3: Paired Project week&lt;br&gt;
-Friday week 3: Project Showcase&lt;/p&gt;
&lt;h2&gt;
  
  
  A day in the life
&lt;/h2&gt;

&lt;p&gt;I did my bootcamp in person (until the quarantine hit) because I know myself to learn best in a community, and one of the more nerve-wracking things about starting bootcamp is not knowing what to expect in the standard day to day schooling. Here is an idea of what a day would be like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;9:00AM : School "starts"
9:15AM : Morning Roll Call
9:30AM : Morning standup - 
    Morning standup is a routine where, before getting started on the day, 
    students stand and talk to their table about what they accomplished the day before, 
    what they plan to accomplish today, what mental or physical blockers may prevent 
    that accomplishment, and how they plan to address those blockers. It's a nice 
    thought exercise to get the day started!
10/11AM: (mandatory) Morning lecture -
     Usually an hour long, it covered the topics we were learning for 
     the day and/pr reviewed the previous days topics.
3:30PM : (optional) Mid-day Madness - 
    Unfortunately with the quarantine these happened less, but they were fun mini-lectures 
    where instructors would have problems for us to work, introduce fun (but un-neccesary) 
    aspects of coding, answers questions or do coding exercises. These were a lot of fun.
5:30PM : End of Day - 
    Students gather and talk about their day, usually highlighting one key thing they 
    learned/were proud of, and any issues they overcame.
6:00PM : Class is done!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You'll notice a &lt;em&gt;lot&lt;/em&gt; of the day is empty or unscheduled. While it's true there were intermittent meetings or guest lectures (Career guidance, resume building, in field experience, etc) a vast majority of the day was "free time" that we worked on a series of labs and readmes. At our school it was common to have a few lessons that were informative and basic background, one or two interactive labs that walked you through a concept, and then series of labs to expand your knowledge by giving you more complex tasks and challenges. At Flatiron they have a series of tests that you run your code against regularly that helps guide you in your quest for knowledge, but a vast majority of your learning comes from trial and error and constant internet searches. As a software engineer you can expect at least 50% of your time spent reading documentation or searching forums for ways to address issues, so be prepared to hone your Google-Fu.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Challenge
&lt;/h2&gt;

&lt;p&gt;Every Mod had a code challenge, designed to test our knowledge and application of the broad foundational subject material we learned over the preview two weeks (or so). They were timed, usually about and hour and a half, and the entire class did them together in one of the larger conference rooms. Looking back now, they are fairly basic applications of coding for each concept, but I was thankful for Flatiron's policy on allowing 1 retake of each code challenge as I failed all but the one initially. This brings me to one of my biggest takeaways from my experience...&lt;/p&gt;

&lt;h2&gt;
  
  
  You will probably not remember most of what you learned in bootcamp.
&lt;/h2&gt;

&lt;p&gt;It is extremely easy to get overwhelmed by the extreme amount of knowledge you are presented at a bootcamp, and it is practically impossible to retain all of it...even if you could, technology changes so quickly that you will have to learn something else new in a few more years at most! My recommendations for focusing on learning any coding are the follows:&lt;/p&gt;

&lt;h4&gt;
  
  
  Learn how you learn
&lt;/h4&gt;

&lt;p&gt;Everyone is geared towards absorbing information differently. I almost &lt;em&gt;have&lt;/em&gt; to make or do something with my hands for it to retain mentally, so pure reading or lectures are actually pretty ineffective of a learning tool for me, but my wife is the exact opposite. On top of that, every type of information will probably need it's own nuance and uniqueness to make it fit you best. Figure out what helps make learning programming most effective for you and stick with it! I have gotten used to using &lt;a href="//draw.io"&gt;draw.io&lt;/a&gt; for planning project outlines, and &lt;a href="https://mindnode.com/"&gt;Mind Node&lt;/a&gt; for brainstorming, and I do a lot of code along videos when learning new methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  Focus on the base concepts of coding
&lt;/h4&gt;

&lt;p&gt;If you stick with programming long enough, you will pretty much &lt;em&gt;have&lt;/em&gt; to learn more than one language eventually. Every coding language has it's pros and cons, and I am neither educated enough nor brave enough to debate with any software engineer what the "best" language is...but almost every language has a lot of common base elements. As you learn more languages you will actually pick up on the ways that most languages are different more than trying to figure out what they have in common, so don't feel bad about having to look up syntax or rules or what certain functions do. Those will come more familiar with time!&lt;/p&gt;

&lt;h4&gt;
  
  
  Advice to those learning to code
&lt;/h4&gt;

&lt;p&gt;Regardless of how you learn, but especially if it's self taught or self guided, you will have a whole gaggle of resources you find online. Start early on getting a decent system of bookmarks to help organize the various sites you see and want to go back to. I have a Ruby folder, a Github folder, and Authentications folder...just anything that makes sense to you so that you can file away resources to find easier next time.&lt;/p&gt;

&lt;p&gt;You also need to learn to fail gracefully. Nobody programs perfect code 100% of the time, and the joy (and challenge) of coding is the puzzle that needs to be solved to get it to work. Sometimes it's your own error you can fix, and sometimes it's something in a system or a file you are dependant on for your program to work. An error doesn't mean it's broken or that you are dumb/wrong/can't do this. An error is just the next stop on the path to functional code. Get used to errors. Love them, despise them, dread them...they will be with you forever once you get in tech.&lt;/p&gt;

&lt;p&gt;Lastly, find a community! There are huge collections of people who are learning these skills, and a wealth of supportive individuals who will happily help you out. That being said, like every industry there are plenty of "gatekeepers" who will try to shame you or judge you on your lack of knowledge...just remember to keep your own positivity up and that being a good team member and empathetic/passionate person is just as desirable for employment as a skillset like coding, and it's a lot easier to learn to code!&lt;/p&gt;

&lt;p&gt;Good luck y'all, and happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Ruby Newby, Testing with rspec part I</title>
      <dc:creator>Dane Dawson</dc:creator>
      <pubDate>Thu, 17 Sep 2020 21:39:24 +0000</pubDate>
      <link>https://forem.com/danedawson/ruby-newby-testing-with-rspec-part-i-1ilo</link>
      <guid>https://forem.com/danedawson/ruby-newby-testing-with-rspec-part-i-1ilo</guid>
      <description>&lt;p&gt;Welcome back!  Today I am going to talk about testing, and why it's so important. &lt;/p&gt;

&lt;p&gt;(As a note, this article is meant for absolute beginners with writing and performing test cases, future articles will go more in depth)&lt;/p&gt;

&lt;h1&gt;Types of testing&lt;/h1&gt;

&lt;p&gt;There are as many applications of testing as there are types of programmers, and as you delve deeper into the world of programming you will find that every person and organization has their own structure and approach to how they design and implement tests. For now let's focus on the two main approaches to writing code on a foundational level.&lt;/p&gt;

&lt;h3&gt;BDD&lt;/h3&gt;

&lt;p&gt;Behavior Driven Development -&amp;gt; Most likely as you begin your coding experience this is what you are used to. The programmer imagines a behavior they want to code to mimic/create, and attempts to write code that creates the results they want. For example, if I wanted a program that told me a personalized greeting when given a name I would start by trying to code something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Hello &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;...And if it didn't work I would tweak/troubleshoot/debug until I got the response I wanted. The idea is your code is driven by the behavior you want it to perform directly.&lt;/p&gt;

&lt;h3&gt;TDD&lt;/h3&gt;

&lt;p&gt;Test Driven Development -&amp;gt; Write a test for the results you want to accomplish and then attempt to write the least amount of code to pass the test. Further refine your code by adding more tests to allow your code to be more precise. The following pseudocode is not syntax accurate, but gives more legible examples of a sequence of tests that one might develop to get to the same function we have as above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;    &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s1"&gt;'hello(name)'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="c1"&gt;#first test is to make sure the function returns a greeting&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;"Method hello(name) includes the word Hello"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="kp"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
        &lt;span class="c1"&gt;#second test ensures the greeting is personalized&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;"Method hello(name) includes the given name"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Joe"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="kp"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Joe"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
        &lt;span class="c1"&gt;#third test is for the precise return desired with given name&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;"Method hello(name) says "&lt;/span&gt;&lt;span class="no"&gt;Hello&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;given&lt;/span&gt; &lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Joe"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello Joe!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In true TDD one would write the first test, then write code to suit that test, then expound further with each additional test.&lt;/p&gt;

&lt;p&gt;The benifits of testing to systems are multifaceted, but the most common reason you will utilize tests is for debugging. All code requires maintenence and upkeep, and especially as you gain more experience and contribute to more projects it will be literally impossible to remember the nuance or specificity about why you have code written the way you do...not to mention, each individual project may grow/evolve in a way that it's easy to forget the minutiae that interconnects all your methods and functions.&lt;br&gt;
Adding tests to your project gives you means to verify existing code you modify or new code you add to your project doesn't alter the existing code base in a way that you aren't expecting. Although best code practices help minimize the likelihood of this kind code interference it's impossible to remember the way every single line of your code interacts with every other line of code throughout your whole project.  Built in tests give you a way to add a series of checks that can be run as frequently as you want to make sure that your project is growing in the direction you want.&lt;/p&gt;

&lt;h1&gt;Implementing&lt;/h1&gt;

&lt;p&gt;I could (and maybe will eventually) write a whole article about the history of tests and the ways they are used by organizations of various sizes, but for now I just want to focus on the very basics of test writing.&lt;/p&gt;

&lt;p&gt;I will be using rspec for my examples, and will currently be operating under the assumption you already know how to install and set up rspec within your code. If not, &lt;a href="https://medium.com/@amliving/my-rails-rspec-set-up-6451269847f9"&gt;here&lt;/a&gt; is an example blog post about setting up your rspect environment.&lt;/p&gt;

&lt;p&gt;The basic outline for creating a test in rspec is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;RSpec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;ClassObject&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s1"&gt;'#new'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;"Generates a new ClassObject with name Hello World"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
            &lt;span class="n"&gt;newObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ClassObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Hello World"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello World"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The test is wrapped in RSpec.describe (name of the model/object you are testing) do-&amp;gt;end. Within the test you can create describe blocks, which will create an ExampleGroup. This is basically a class in which "it" blocks are passed and evaluated, each block existing within a unique instance of that tested class. Every "it" method within the describe block becomes a test case in which you give the parameters of your test and your expected results. This article is solely to introduce the base form of testing, but feel free to look &lt;a href="https://relishapp.com/rspec/"&gt;here&lt;/a&gt; at one of the more comprehensive syntax/vocabulary guides I have found regarding rspec's many applications.&lt;/p&gt;

&lt;p&gt;I have created a very simple series of tests to show initial implementation and foundation for rspec testing. If you were to create these files in a ruby repository with the rspec gem installed they can be run and shown to pass.&lt;/p&gt;

&lt;p&gt;First is the class, which I have classed Thingdoer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;#thingdoer.rb&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Thingdoer&lt;/span&gt;

    &lt;span class="c1"&gt;#The first test is set to see if the method equals "Hello". &lt;/span&gt;
    &lt;span class="c1"&gt;#Simple test just to show framework and how to use expect().to&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;return_hello&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Hello"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="c1"&gt;#This second function has the same test written and also passes. &lt;/span&gt;
    &lt;span class="c1"&gt;#This works because Ruby implicitly returns &lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;
        &lt;span class="s2"&gt;"Hello"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="c1"&gt;#This test would fail with the the previous testing parameter, &lt;/span&gt;
    &lt;span class="c1"&gt;#because although it puts "Hello", the method itself does &lt;/span&gt;
    &lt;span class="c1"&gt;#not return "Hello". The test has been changed to pass by &lt;/span&gt;
    &lt;span class="c1"&gt;#altering the expect().to into expect().not_to&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello_fail&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Hello"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="c1"&gt;#One more example to show that the last string in the &lt;/span&gt;
    &lt;span class="c1"&gt;#function is the one returned, the test for this function &lt;/span&gt;
    &lt;span class="c1"&gt;#checks for "Goodbye".&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;return_goodbye&lt;/span&gt;
        &lt;span class="s2"&gt;"Hello"&lt;/span&gt;
        &lt;span class="s2"&gt;"and"&lt;/span&gt;
        &lt;span class="s2"&gt;"Goodbye"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="c1"&gt;#This test shows a way to use include testing. &lt;/span&gt;
    &lt;span class="c1"&gt;#Use include to specify that a collection includes &lt;/span&gt;
    &lt;span class="c1"&gt;#one or more expected objects. Note that even though &lt;/span&gt;
    &lt;span class="c1"&gt;#there are two entries, include only tests if *any* &lt;/span&gt;
    &lt;span class="c1"&gt;#object passes the condition&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;say_hello&lt;/span&gt;
        &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"and"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Goodbye"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And as is required by rspec, the tests are saved within the spec folder and following naming requirements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;#spec/thingdoer_spec.rb&lt;/span&gt;
&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'thingdoer'&lt;/span&gt;

&lt;span class="no"&gt;RSpec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Thingdoer&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s1"&gt;'#hello'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s1"&gt;'Method hello should equal Hello'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Thingdoer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;


    &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s1"&gt;'#return_hello'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;"Method return_hello returns value of 'Hello'"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Thingdoer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;return_hello&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s1"&gt;'#return_goodbye'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s1"&gt;'Method return_goodbye should equal GoodBye'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Thingdoer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;return_goodbye&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;not_to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Thingdoer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;return_goodbye&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;not_to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"and"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Thingdoer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;return_goodbye&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Goodbye"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s1"&gt;'#hello_fail'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s1"&gt;'Method hello_fail should *not* equal Hello'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Thingdoer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hello_fail&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;not_to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="s1"&gt;'#say_hello'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s1"&gt;'Method say_hello should include Hello'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Thingdoer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="kp"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Thingdoer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;not_to&lt;/span&gt; &lt;span class="kp"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Welcome"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hopefully this will make it a little easier for someone else trying to get started writing tests, I know my first test was an incredibly overwhelming undertaking. I am in the process of creating a simple rails app with testing at all the various levels for upcoming blog posts, so hopefully I will see you back here again soon!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rspec</category>
      <category>testing</category>
    </item>
    <item>
      <title>Staying focused coding from home part 1!</title>
      <dc:creator>Dane Dawson</dc:creator>
      <pubDate>Fri, 11 Sep 2020 02:21:02 +0000</pubDate>
      <link>https://forem.com/danedawson/staying-focused-coding-from-home-part-1-10n1</link>
      <guid>https://forem.com/danedawson/staying-focused-coding-from-home-part-1-10n1</guid>
      <description>&lt;p&gt;I just graduated from Flatiron as a software engineer, and even though I just spent over 3 months diligently studying and working on projects and lessons and learning so much, one of the things I have found extremely difficult is staying productive and focused now that I don't have that framework.  I know I am intelligent and clever, and my logical brain realizes how important it is to stay on top of things and continue to work on developing my skills and networking, but let's be honest...The world is in a weird place right now and even in the best of times it's easy to lean back and let the current take you where it wants to.  I decided to share some of the tricks and tips I am using to keep myself motivated, accountable, and driven. If you find them useful, great! If you have extra tips or advice, also great! I will try to keep this updated as I see how I react to things and what resonates with me or not and why.&lt;/p&gt;

&lt;h1&gt;
  
  
  Habit tracking
&lt;/h1&gt;

&lt;p&gt;There are &lt;a href="https://www.richarddally.com/why-are-checklists-so-powerful/"&gt;plenty&lt;/a&gt; of &lt;a href="https://bizfluent.com/info-8199048-advantages-disadvantages-using-checklist.html"&gt;sites&lt;/a&gt; that &lt;a href="https://www.hartfordbusiness.com/article/seven-management-benefits-of-using-a-checklist"&gt;can&lt;/a&gt; teach &lt;a href="https://www.process.st/daily-task-checklist/"&gt;all&lt;/a&gt; kinds of pros and cons to checklists, but personally I find them a great way to organize my train of thought and begin to break things down into actionable tasks rather than nebulous anxiety sources. You can find all kinds of &lt;a href="https://www.process.st/checklists-in-the-workplace/"&gt;methods&lt;/a&gt; and &lt;a href="https://lifehacker.com/how-to-use-simple-checklists-to-boost-efficiency-and-re-1721805002"&gt;styles&lt;/a&gt; you can use, I'll walk through my starting point when I approach any new project whether it's coding or cleaning the closet:&lt;/p&gt;

&lt;p&gt;-Figure out the scope of this "task". I know this seems arbitraty, but for any project it's easy to get distracted or overly enthusiastic at some point and end up re-organizing your bookshelf when you started sweeping your floors. Whether it's deciding that your starting MVP for the project will have only 4 models and bare-bones interfacing or specifying you will be focusing on yardwork in the front yard specifically, giving yourself an end goal (even if there are more steps in the future!) will make it easier to "finish" and feel accomplished.&lt;br&gt;
-Break the task in to as few "large" sub-tasks as you can. For our yardwork metaphor, it could be knowing you have to (Mow, Weed-whack/edge the sidewalk, tend the planting beds, Pick up the disaster area your kids left, Sweep/wash the sidewalk and driveway) or for our coding metaphor it could be (Set up backend models, create routes/database interaction, set up frontend, create simple user interface). &lt;br&gt;
-This is where you can pick what works best for you. Personally, I like to take each large task and break it down into almost as small of an &lt;a href="http://www.textfugu.com/season-1/japanese-pronunciation/3-2/"&gt;"actionable task"&lt;/a&gt; as you can. This lets you take time to actually plan and organize your project and method of approach and, when done correctly, can vastly minimize the amount of double-work or corrections you might have to make. I tend to go into the overkill on this personall, where I will take a large task and break it into smaller tasks, and then break of those tasks into smaller tasks still, until I get things that I can accomplish in 30 minutes to an hour. This makes it easier for the next step:&lt;br&gt;
-Check things off!! You did it! I know it's easy to feel like a small task is meaningless, but it's even easier to not do that task at all. Allow yourself to feel proud and get a nice dopamine release, you earned it! This is the part that helps me the most...It's common tendency to think that it's not worth celebrating an achievement until the "big picture" is finished, but if you do this you are vastly under appreciating your worth. The largest, greatest, and most impactful things in history were build one piece at a time, allow yourself to appreciate every step of the journey for what it is: the results of your hard work and dedication.&lt;/p&gt;

&lt;p&gt;//This area talk about benefits of habit tracking maybe?&lt;/p&gt;

&lt;h1&gt;
  
  
  Accountability (Accountabili-buddies!)
&lt;/h1&gt;

&lt;p&gt;Me and a few friends have started using &lt;a href="//www.habitica.com"&gt;Habitca&lt;/a&gt; as a way to track our tasks. This combines all the wonderful things I have mentioned above with task-lists and habit tracking, but one of my greatest constant motivators is mutual accountability. Find a group of people you trust and respect (even if it's just one person!) and talk to each other about what you are doing. Share your task lists (full details or just highlights), talk about what's going on and what your gameplan is. An idea in our head can be ethereal and lofty, but having someone you can be open and honest with about your progress (or lack there-of) can help you both stay on task and grow. Some tips for people making/forming Accountabili-buddy groups:&lt;/p&gt;

&lt;p&gt;-The only criticism is &lt;a href="https://personalexcellence.co/blog/constructive-criticism/"&gt;constructive criticism&lt;/a&gt;. You are here to support and improve not only yourself but everyone in your group, negativity will only create more negativity.&lt;br&gt;
-Be open and upfront with what you want from the group. If you want someone to message you every day and make sure you are on task, let it be known...but on the flip side, if you want to keep to yourself and have the group there for questions or specific feedback, that is fine too! Take the time early on to set boundaries and expectations, I know it feels clinical and abnormal but it will save you a lot of misunderstanding later on!&lt;br&gt;
-Respect each other. This kind of group activity is opening yourself up to a level of vulnerability that can be easy to underestimate. Allow yourself to be patient and kind in every interaction, the best accountabili-buddy is stern but supportive.&lt;/p&gt;

&lt;p&gt;&lt;a href="//www.habitica.com"&gt;Habitca&lt;/a&gt; has (thusfar) been a great resource, it allows us to have private lists of things we are tracking or (in the paid version) group tasks that we can all do/track together. &lt;/p&gt;

&lt;h1&gt;
  
  
  Compartmenting spaces
&lt;/h1&gt;

&lt;p&gt;Set up a work area! It's that easy! The harder part is making sure it's the &lt;em&gt;only&lt;/em&gt; place you work. There are plenty of sites to tell you ways to organize your home work space, &lt;a href="https://www.erinflynn.com/create-functional-work-space/"&gt;tips&lt;/a&gt; and &lt;a href="https://www.sparefoot.com/self-storage/blog/20173-6-steps-to-create-the-perfect-workspace-at-home/?irgwc=1&amp;amp;tsid=impact&amp;amp;utm_source=impact&amp;amp;utm_medium=affiliate&amp;amp;utm_campaign=123201&amp;amp;click_id=SRAXDrylxxyOW-3wUx0Mo3cgUkiwWzQp3yzmQQ0&amp;amp;utm_content=Online%20Tracking%20Link_ONLINE_TRACKING_LINK&amp;amp;ad_id=483123&amp;amp;campaign_id=8436&amp;amp;ad_size=&amp;amp;partner_name=adgoal%20GmbH"&gt;tricks&lt;/a&gt; about ways to design your space. I could (and may eventually) write a whole post just about setting up an ergonomic and functional workspace, but the key thing I want to focus on is true regardless of what your setup at home is.&lt;/p&gt;

&lt;p&gt;-Designate a "work only" space. Your brain is surprisingly good at catching onto habits, both good or bad. If we use the same table/counter/desk to do all of our work at, we train our mind that this location is &lt;em&gt;for&lt;/em&gt; working, and will be much easier to stay focused and guided in that direction.&lt;br&gt;
-Honor the "work only" space. Avoid doing &lt;em&gt;anything&lt;/em&gt; that isn't work related at your work area. As soon as your start to spend time browsing Reddit or perusing Amazon at your work station your brain is going to get distracted. Is this a place where we focus on work, or a place for recreation?&lt;/p&gt;

&lt;p&gt;Its important not to bite off more than you can chew! Trying to change too much at once will only make you feel overwhelmed, focus on one habit/task at a time. &lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Ruby Newby, introduction to Rails associations and their potential</title>
      <dc:creator>Dane Dawson</dc:creator>
      <pubDate>Wed, 06 May 2020 12:47:01 +0000</pubDate>
      <link>https://forem.com/danedawson/ruby-newby-introduction-to-rails-associations-and-their-potential-5cmp</link>
      <guid>https://forem.com/danedawson/ruby-newby-introduction-to-rails-associations-and-their-potential-5cmp</guid>
      <description>&lt;p&gt;One of the more useful tools that comes with Ruby on Rails is associations. This allows you to set up relationships between models to use built in functions to stream line your code for commonly used interactions. I will be heavily referring to the documentation included with &lt;a href="https://guides.rubyonrails.org/association_basics.html"&gt;Ruby on Rails&lt;/a&gt;, which I would recommend reading through when you have the time. For now I will highlight the most basic relationships that one is likely to use.&lt;/p&gt;

&lt;p&gt;Associations make it easier to get models to have a connection that can be instantly referenced, allowing a coder to make a reference to a single model and, with that reference, also get information on all it's associated models. &lt;/p&gt;

&lt;p&gt;Here are the relationships that come default with Rails and the ones you will interact with most:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;belongs_to&lt;/li&gt;
&lt;li&gt;has_one&lt;/li&gt;
&lt;li&gt;has_many&lt;/li&gt;
&lt;li&gt;has_many :through&lt;/li&gt;
&lt;li&gt;has_one :through&lt;/li&gt;
&lt;li&gt;has_and_belongs_to_many&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To talk about what the differences between each relationship is I'll use a music app metaphor that is pretty common.&lt;/p&gt;

&lt;p&gt;Let's start with the has_many and belongs_to: Any song written by that songwriter belongs to them, and couldn't exist if they weren't there to write it, so in the song model we would write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Song&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:singer&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And, because out singer owns the songs, we will change their model accordingly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Singer&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:songs&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will allow you to, in the console, type out&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Singer.first.songs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And it will give you the models of each song associated with the first singer in the database!&lt;br&gt;
The current setup makes the song model dependant and makes it to where a song can't be saved to the database unless you assign it to a singer. This can be useful in database management and also a source of debugging stress if you forget!&lt;/p&gt;

&lt;p&gt;Note, because the singer will write more than one song it is a has_many and thus songs needs to be plural. &lt;br&gt;
 A good example of a has_one could be the singer's alias. Marshall Bruce Mathers III has_one professional alias, and it's Eminem. The use of has_one is benificial because it's not dependant. Let's add the steps for our alias class and singer class updates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Singer&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:songs&lt;/span&gt;
&lt;span class="n"&gt;has_one&lt;/span&gt; &lt;span class="ss"&gt;:alias&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="sr"&gt;//&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Alias&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:singer&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice that the has_one is singular!  Now let's talk about through associations...Everyone knows that a well rounded artist doesn't shoehorn themselves into only one genre and style of music, wouldn't it be nice if we could find out what kind of genres a musician has performed with one simple keystroke? Let's set that up!&lt;/p&gt;

&lt;p&gt;First, we need to show that songs can have genres. For simplicity sake we are going to say that every song has only one genre, so let's set up that relationship first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Song&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:singer&lt;/span&gt;
&lt;span class="n"&gt;has_one&lt;/span&gt; &lt;span class="ss"&gt;:genre&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="sr"&gt;//&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Genre&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:song&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here's the fun part! We already know the song is associated with the singer, and the genre is associated to the song, all we have to is pass that connection along the chain! Our final set of model associations would look as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Singer&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:songs&lt;/span&gt;
&lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:genres&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;through: :songs&lt;/span&gt;
&lt;span class="n"&gt;has_one&lt;/span&gt; &lt;span class="ss"&gt;:alias&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="sr"&gt;//&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Song&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:singer&lt;/span&gt;
&lt;span class="n"&gt;has_one&lt;/span&gt; &lt;span class="ss"&gt;:genre&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="sr"&gt;//&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Genre&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:song&lt;/span&gt;
&lt;span class="sr"&gt;//&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Alias&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
&lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:singer&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will allow you to do things like the following which can make backend database management a lot easier and smoother.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Singer.first.genres
 Singer.first.alias
 Song.first.singer
 Song.first.genre
 Alias.first.singer
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Until next time, happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Checklist for HTTP Rails/React user auth setup - Rails backend setup checklist.</title>
      <dc:creator>Dane Dawson</dc:creator>
      <pubDate>Wed, 06 May 2020 12:19:15 +0000</pubDate>
      <link>https://forem.com/danedawson/checklist-for-http-rails-react-user-auth-setup-rails-backend-setup-checklist-7nc</link>
      <guid>https://forem.com/danedawson/checklist-for-http-rails-react-user-auth-setup-rails-backend-setup-checklist-7nc</guid>
      <description>&lt;p&gt;This article is written as a destilling of &lt;a href="https://www.youtube.com/watch?v=z18zLCAg7UU&amp;amp;list=PLgYiyoyNPrv_yNp5Pzsx0A3gQ8-tfg66j&amp;amp;index=1"&gt;this&lt;/a&gt; video series by &lt;a href="https://www.youtube.com/user/edutechional"&gt;Edutechional&lt;/a&gt;. If this is your first time creating a user authentication with Rails and React I would highly recommend watching the 10 video series to understand what is going on. I also recommend any of other videos he offers, his way of explaining is straightforward and easy to understand. If, however, this isn't your first time setting up a back end cookie based user auth and you just want a nitty gritty checklist of an auth framework, you've come to the right place! I tried to grab every bit of code needed to get it working with minimal descriptions to streamline flow. Good luck.&lt;/p&gt;




&lt;p&gt;-Create new app in Rails with a pstgresql database and create the database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails new app_name --database=postgresql
rails db:create
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;-Get latest version of &lt;a href="https://rubygems.org/gems/bcrypt"&gt;bcrypt&lt;/a&gt; in your gemfile as well as rack-cors. At the time of writing this article:&lt;/p&gt;

&lt;h4&gt;
  
  
  Gemfile
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'bcrypt'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'~&amp;gt; 3.1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&amp;gt;= 3.1.13'&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'rack-cors'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:require&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'rack/cors'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;-update gems with console command of preference, I use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  create file app/config/intilizers/cors.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert_before&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Rack&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Cors&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="c1"&gt;#first origin is your API host address&lt;/span&gt;
    &lt;span class="n"&gt;allow&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;origins&lt;/span&gt; &lt;span class="s2"&gt;"http://localhost:3000"&lt;/span&gt;
        &lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;headers: :any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;methods: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:get&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:put&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:patch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:delete&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:head&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;credentials: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="c1"&gt;#second origin is front end host address&lt;/span&gt;
    &lt;span class="n"&gt;allow&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;origins&lt;/span&gt; &lt;span class="s2"&gt;"http://app_name.herokuapp.com"&lt;/span&gt;
        &lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;headers: :any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;methods: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:get&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:put&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:patch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:delete&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:head&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;credentials: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  create file app/config/intilizers/session_store.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;#key is how you want it to be identified in cookies, domain is same as above in cors file&lt;/span&gt;
&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;session_store&lt;/span&gt; &lt;span class="ss"&gt;:cookie_store&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;key: &lt;/span&gt;&lt;span class="s2"&gt;"_appname"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;domain: &lt;/span&gt;&lt;span class="s2"&gt;"app_name.herokuapp.com"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  app/config/routes.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"static#home"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  create file app/controllers/static_controller.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StaticController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;home&lt;/span&gt;
        &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;status: &lt;/span&gt;&lt;span class="s2"&gt;"It's working"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  ************
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Check point
&lt;/h1&gt;

&lt;h1&gt;
  
  
  ************
&lt;/h1&gt;

&lt;p&gt;You should be able to visit your backend host (My example is &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt;) and have it show the json string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"It's working"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;-Create your user model, it must have a password_digest attribute. I am also adding email for validation. Then migrate models.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails g model User email password_digest
rails db:migrate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  app/models/user.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
    &lt;span class="n"&gt;has_secure_password&lt;/span&gt;
    &lt;span class="c1"&gt;#sets email as required attribute for model creation&lt;/span&gt;
    &lt;span class="n"&gt;validates_presence_of&lt;/span&gt; &lt;span class="ss"&gt;:email&lt;/span&gt;
    &lt;span class="c1"&gt;#validates unique emails&lt;/span&gt;
    &lt;span class="n"&gt;validates_uniqueness_of&lt;/span&gt; &lt;span class="ss"&gt;:email&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  ---Quick check---
&lt;/h2&gt;

&lt;p&gt;If you did this correctly then you should be able to create a user in the Rails console and it should store a user model with an encrypted password_digest. User creation should look like this for encryption:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.create(email: "email@address.com", password: "password", password_confirmation: "password")
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  app/config/routes.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:sessions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;only: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:create&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:registrations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;only: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:create&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"static#home"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  Create app/controllers/sessions_controller.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SessionsController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
        &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;email: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nf"&gt;try&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:authenticate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;"password"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;
            &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:user_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;
            &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="ss"&gt;status: :created&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="ss"&gt;logged_in: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="ss"&gt;user: &lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;status: &lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  Create app/controllers/registrations_controller.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RegistrationsController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
        &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="ss"&gt;email: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="ss"&gt;password: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="ss"&gt;password_confirmation: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'password_confirmation'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;
            &lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:user_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt; 
            &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="ss"&gt;status: &lt;/span&gt;&lt;span class="n"&gt;created&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="ss"&gt;user: &lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;status: &lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  app/controllers/application_controller.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApplicationController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActionController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;
    &lt;span class="n"&gt;skip_before_action&lt;/span&gt; &lt;span class="ss"&gt;:verify_authenticity_token&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  ************
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Check point
&lt;/h1&gt;

&lt;h1&gt;
  
  
  ************
&lt;/h1&gt;

&lt;p&gt;To test the current interactions, start the rails server and in another terminal interface do the following (user info should be the same as the user created at previous checkpoint). Use your hosting address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --header "Content-Type: application/json" \
--request POST \
--data '{"user": {"email": "z@dev.com", "password": "asdf"}}' \
http://localhost:3000/sessions
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You should get some message similar to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"status":"created","logged_in":true,"user":{"id":1,"email":"z@dev.com","password_digest":"$2a$12$m9er4Bkndom7g5I85Ppj0Ob8EoPYkcw/gApT1ofEz2Ld3y4Eopbzy","created_at":"2020-04-26T02:15:57.844Z","updated_at":"2020-04-26T02:15:57.844Z"}}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  app/config/routes.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:sessions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;only: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:create&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:registrations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;only: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:create&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:logout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"sessions#logout"&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="ss"&gt;:logged_in&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"sessions#logged_in"&lt;/span&gt;
  &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="s2"&gt;"static#home"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  Create app/controllers/concerns/current_user_concern.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;CurrentUserConcern&lt;/span&gt; 
    &lt;span class="kp"&gt;extend&lt;/span&gt; &lt;span class="no"&gt;ActiveSupport&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Concern&lt;/span&gt;

    &lt;span class="n"&gt;included&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;before_action&lt;/span&gt; &lt;span class="ss"&gt;:set_current_user&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;set_current_user&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sessions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:user_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="vi"&gt;@current_user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:user_id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  app/controllers/sessions_controller.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SessionsController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
    &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;CurrentUserConcern&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
        &lt;span class="c1"&gt;#unchanged&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;logged_in&lt;/span&gt; 
       &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@current_user&lt;/span&gt;
            &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="ss"&gt;logged_in: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="ss"&gt;user: &lt;/span&gt;&lt;span class="vi"&gt;@current_user&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="ss"&gt;logged_in: &lt;/span&gt;&lt;span class="kp"&gt;false&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
       &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;logout&lt;/span&gt;
        &lt;span class="n"&gt;reset_session&lt;/span&gt;
        &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;status: &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;logged_out: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h4&gt;
  
  
  app/config/initializers/session_store.rb
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"production"&lt;/span&gt;
    &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;session_store&lt;/span&gt; &lt;span class="ss"&gt;:cookie_store&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;key: &lt;/span&gt;&lt;span class="s2"&gt;"_homesteadtogether"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;domain: &lt;/span&gt;&lt;span class="s2"&gt;"jdh-homesteadtogether.herokuapp.com"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;session_store&lt;/span&gt; &lt;span class="ss"&gt;:cookie_store&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;key: &lt;/span&gt;&lt;span class="s2"&gt;"_homesteadtogether"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Finished!
&lt;/h1&gt;

&lt;p&gt;That should complete the backend of the api. I will try to compress this into more concise single page paragraphs in the future. Working on the front end walkthrough now.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fetch() in JavaScript pt. II, Revenge of the options</title>
      <dc:creator>Dane Dawson</dc:creator>
      <pubDate>Sat, 25 Apr 2020 23:57:01 +0000</pubDate>
      <link>https://forem.com/danedawson/fetch-in-javascript-pt-ii-revenge-of-the-options-3775</link>
      <guid>https://forem.com/danedawson/fetch-in-javascript-pt-ii-revenge-of-the-options-3775</guid>
      <description>&lt;p&gt;Where we last left off at &lt;a href="https://dev.to/danedawson/introduction-to-fetch-in-javascript-2imd"&gt;my first post about fetch()&lt;/a&gt; we have the ability to use fetch to perform GET requests. For POST, PATCH, and DELETE, we will need to utilize the options I referred to in the last article.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;METHOD&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;dataKey1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dataValue1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dataKey2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dataValue2&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There are numerous and nuanced ways to set up fetch requests, and for more detailed information I would recommend looking &lt;a href="https://javascript.info/fetch"&gt;here&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch"&gt;here&lt;/a&gt;, or googling around if you need a particular approach. This walkthrough is simply a very basic, functional application of CRUD functionality for fetch requests designed to introduce new programmers and open the door to the possibilities of fetch().&lt;/p&gt;

&lt;p&gt;Let me try to break down what each of those aspects can be used for&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;//This is where you specify what type of request you are sending.&lt;/span&gt;
      &lt;span class="c1"&gt;//This article will cover a basic application of POST, PATCH, and DELETE&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;METHOD&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="c1"&gt;//I only got the kind of graze the surface of what headers do. &lt;/span&gt;
      &lt;span class="c1"&gt;//From my understanding they are a way for the backend and front end&lt;/span&gt;
      &lt;span class="c1"&gt;//verify they are sending the same type of information in the same way.&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="c1"&gt;//This is the actual content you are sending, you can think of it as either&lt;/span&gt;
      &lt;span class="c1"&gt;//a ruby hash or a JavaScript object (the latter is more accurate). Fetch&lt;/span&gt;
      &lt;span class="c1"&gt;//exchanges JSON strings of data, so we have to convert our data object&lt;/span&gt;
      &lt;span class="c1"&gt;//into a JSON string.&lt;/span&gt;
      &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;dataKey1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dataValue1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dataKey2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dataValue2&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is the basic outline of what all three of these fetch functions will look like, with some minor alterations depending on what the function is.&lt;/p&gt;

&lt;h2&gt;
  
  
  POST
&lt;/h2&gt;

&lt;p&gt;The following is an example of one way you could set up a POST request to a simple backend API to create a new user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//setting global constant for the user database URL&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userURL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://localhost:3000/users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;//This is the user object we are adding to the database. &lt;/span&gt;
&lt;span class="c1"&gt;//This model is fairly simple, but it could contain as many attributes as you would like.&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mordecai Phineaus III&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mordiphi@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//by creating the postOption as an object, it makes it easier to call within the fetch&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;postOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json;charset=utf-8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userURL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;postOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//Note: the following code is functionally identical to the fetch above&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://localhost:3000/users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json;charset=utf-8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mordecai Phineaus III&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mordiphi@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="c1"&gt;//You can see how it can be easier to follow if you use variables&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  PATCH
&lt;/h2&gt;

&lt;p&gt;Recent updates to Rails and JavaScript have made a PATCH request much simpler. If the back end is properly set up all you have to do is target the object you want to alter and send a similar options object as the POST. See the differences below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userURL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://localhost:3000/users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;//For this example, let's imagine this is the model for the user object we are updating.&lt;/span&gt;
&lt;span class="c1"&gt;//For simplicity it only has an id, a name, and an email&lt;/span&gt;
&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mordecai Phineaus III&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mordiphi@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//Our user wants to update their email&lt;/span&gt;
&lt;span class="nx"&gt;newEmail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MightyMordiPhineas@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;//As we are only updating the email, we don't need to include any other attributes&lt;/span&gt;

&lt;span class="c1"&gt;//New PATCH request with the updated email as the body&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;patchOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PATCH&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json;charset=utf-8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newEmail&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="c1"&gt;//We will need to find the user in the database to update them&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="c1"&gt;//Now we fetch to the specific id of the model we are trying to update&lt;/span&gt;

&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userURL&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;patchOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;//Note the above single line of code is functionally identical to the following&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:3000/1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json;charset=utf-8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MightyMordiPhineas@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;DELETE is even easier. This is by far the most dirty and straightforward way to do a delete, but especially for your first delete interactions it will work great!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;patchOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userURL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://localhost:3000/users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;//Let's take a look at that user we had before&lt;/span&gt;
&lt;span class="c1"&gt;//note the updated email address as our PATCH was so successful&lt;/span&gt;
&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mordecai Phineaus III&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MightyMordiPhineas@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//Now we just want to delete the file entirely. &lt;/span&gt;

&lt;span class="c1"&gt;//Since no specific information is needed to delete the file other than the user id&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;

&lt;span class="c1"&gt;//Our DELETE option is far cleaner&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;deleteOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DELETE&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="c1"&gt;//Again, we just target the user by their id we captured above&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userURL&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;deleteOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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



&lt;p&gt;Hopefully armed with these base outlines you can get your API and client side connected and start to really explore the potential programming has to offer.&lt;/p&gt;

&lt;p&gt;Until next time, happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>post</category>
      <category>patch</category>
      <category>delete</category>
    </item>
    <item>
      <title>Introduction to  fetch() in JavaScript</title>
      <dc:creator>Dane Dawson</dc:creator>
      <pubDate>Sat, 25 Apr 2020 20:07:35 +0000</pubDate>
      <link>https://forem.com/danedawson/introduction-to-fetch-in-javascript-2imd</link>
      <guid>https://forem.com/danedawson/introduction-to-fetch-in-javascript-2imd</guid>
      <description>&lt;h4&gt;
  
  
  This article series will use Ruby on Rails as a backend and JavaScript as the front end.
&lt;/h4&gt;

&lt;p&gt;As I was learning JavaScript, one of the most confusing aspects of database interactions was the fetch() function. It is one of the most commonly used ways to interact with APIs, and while it has an amazing amount of functionality we will focus on it's most basic application, using the following format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Setting our host URL as a constant for easy reference&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:3000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="c1"&gt;//We will probably not talk much about options this article, but here is an example one&lt;/span&gt;
&lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;METHOD&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;dataKey1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dataValue1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dataKey2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dataValue2&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//This is the actual series of functions for a fetch request. &lt;/span&gt;
&lt;span class="c1"&gt;//However, the above options and URL are just examples of possible text&lt;/span&gt;
&lt;span class="c1"&gt;//This series of code would actually be inneffective in practice &lt;/span&gt;
&lt;span class="c1"&gt;//so we are focusing on the structure rather than specific content.&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;First, let me break down what this series of lines will do at a base level. The first line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will send a request (included in the options) to the specified URL (which we are saying is a local server we are hosting at &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt;). There is a lot to unpack in the options, but the first fetch request almost any app will make is a GET request, pinging the database for some information from the API. One of the wonderful things about fetch is that if you are only doing a GET request you can actually leave the options variable blank and it will assume you are fetching information. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Global constant for database URL&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:3000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="c1"&gt;//Calling fetch on that url&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Will send a GET request to whatever URL you send it. What will happen is fetch will send out a request to that URL, and if the URL is valid, it will return a promise. Most errors you will get at this point are because either the url is entered incorrectly or the database doesn't have the routes connected for request you are making at that URL. It is worth looking into what a promise fully entails, but a good foundational understanding is that the database was reached, the route connected, and it returned a notification saying "I got your request, I will send information as soon as I can". Once the information is retrieved and packaged at the server, it will send a response that is normally a JSON string.&lt;/p&gt;

&lt;h4&gt;
  
  
  Some quick words about asynchronous functions
&lt;/h4&gt;

&lt;p&gt;For me, fetch was the first asynchronous function I had contact with, and it's the asynchronous nature of this function that requires the subsequent .then() functions. Normally, when JavaScript runs, it will read through the entire document once, and then run the code line by line. By nature, most code is synchronous so as soon as one line finishes being read it is computed immediately and the next line is executed. Fetch(), however, knows that it may take time to get the response back from the server, so after running the fetch request it will immediately move on to the next line of code...but our fetch won't have returned anything except a promise!  &lt;/p&gt;

&lt;p&gt;This brings us to the next lines of the fetch chain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Global constant for database URL&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:3000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="c1"&gt;//Calling fetch on that URL. This will instantly return a promise (if URL is valid databse).&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//Then, once the response has been returned, convert the JSON string to an object&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As we now covered, the fetch will first return a promise followed (usually very quickly) by a response. This response will hold all the information pulled from your GET request, but it will hold it in a JSON string. While a JSON string is very useful for data sending (it is one long, easily digestible string with all negative space removed), it is difficult for most humans to interact with a JSON string comfortably. Our first action is to take this string and turn it into something we can actually manipulate, a JSON object. Thankfully, JavaScript has a built in function .json() to turn a JSON string into a JSON object. This, however, is yet another asynchronous function as the system won't know how long it will take to fully convert this string. All this means is we tack on one more .then to take that JSON object and do whatever we want to with it. This example is simply logging the object in the console, which is a good first step with a fetch to make sure you have the data you want in the format you want it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Global constant for database URL&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:3000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="c1"&gt;//Calling fetch on that URL. This will instantly return a promise (if URL is valid databse).&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//Then, once the response has been returned, convert the JSON string to an object&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;//Then, once the string has been converted into an object, console.log the object&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this current setup we have created a URL variable that just hits a server at it's root folder. A practice I have found useful is setting the server locations you will be targeting as global constants. Note, all these names used so far are simply placeholders for legibility in this walkthrough, you can use anything you want to reference the variables. If you were fetching an API to get a collection of users, you may do like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Global constant for user database URL&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userURL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:3000/users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;userURL&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If this works correctly, we should have in our console a list of every user object in our database. You could easily return the users, or embed another function that renders components, divs, or any other application of those objects you want.&lt;/p&gt;

&lt;p&gt;If you wanted to target a specific user by id, you could do a targeted fetch like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Global constant for user database URL&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userURL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:3000/users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="c1"&gt;//You can define this userId through an input value or any other way you'd like&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;//This is the same as typing "http://localhost:3000/users/1" but open to dynamic change&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;userURL&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;//this will now only return the user found at the id given&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that we have the basic foundations of GET requests, all the other requests work very similarly except the presence of the options. &lt;/p&gt;

&lt;p&gt;Click &lt;a href="https://dev.to/danedawson/fetch-in-javascript-pt-ii-revenge-of-the-options-3775"&gt;HERE&lt;/a&gt; to see a basic introduction to full CRUD fetch requests!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>fetch</category>
      <category>options</category>
      <category>get</category>
    </item>
    <item>
      <title>My First Large Programming Project - Lessons Learned</title>
      <dc:creator>Dane Dawson</dc:creator>
      <pubDate>Fri, 14 Feb 2020 18:18:08 +0000</pubDate>
      <link>https://forem.com/danedawson/my-first-large-programming-project-lessons-learned-166e</link>
      <guid>https://forem.com/danedawson/my-first-large-programming-project-lessons-learned-166e</guid>
      <description>&lt;p&gt;I am writing this post now after completing the alpha of my very first project, Ruby Wizard, an interactive text-based game framed to lay foundation for a game introducing new programmers to Ruby. It was a humbling and gratifying experience trying to storyboard and plan a project with a deadline for the first time, but I wanted to take a moment to point out things I picked up along the way I learned during my first real project. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;--You can never plan too much--&lt;/p&gt;

&lt;p&gt;Seems straightforward but the more you can storyboard, whiteboard, brainstorm and draw out before you actually even touch a computer the easier you will find getting everything to connect in the end. It's easier to take an extra day to plan than an extra 2 days to debug! We started basic brainstorming on a combination of GoogleDocs for content and Draw.io to whiteboard our object interactions and map our software layout, and probably spent at least 2 days planning as much as we could before we typed a single word of code.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;--Make small changes with each test, and isolate as much testing as you can--&lt;/p&gt;

&lt;p&gt;My first alters to code were vast and sweeping, adjusting multiple values and methods across several pages all at the same time. It shouldn't be hard to see why this was a terrible idea. I would often spend longer debugging the mess I created than I would have if I just tested along the way. My rule of thumb has become "Every time you make an edit that breaks your code, as soon as it should be fixed check it". If all you do is change one value or variable, save and test immediately. Run things early and often and it saved me a lot of trouble in the later stages of our project debug.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;--Break problems down as small as possible--&lt;/p&gt;

&lt;p&gt;There were many aspects of making a game that were completely overwhelming, especially some of the stretch goals we still have in mind as we continue to tinker with this project in the future. Any task you have ahead will be exponentially easier if you break it into it's smallest compartments.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;--Always check for gems--&lt;/p&gt;

&lt;p&gt;We were doing a game operating entirely through the console, so we already knew that graphical interface was going to be minimal...but we still wanted things to look good! Thankfully, other developers have had the same issue and were kind enough to openly source their solutions. We ended up utilizing TTY-prompt, TTY-box, and TTY-font as our primary display functions...which leads me to my next tip...&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;--Take the time to view the readme on any gem you use!--&lt;/p&gt;

&lt;p&gt;If you find a gem that looks like it may help you out, definitely take the time to go through the whole readme/documentation if possible. During out project we were using boxes to frame data pulled from a database with one method we found in the gem TTY-box. We found the gem for exactly this one purpose we had in mind, and, having accomplished that task, promptly forgot we had the TTY-box gem installed. Later we came across issues with our display output in a context that we spent hours working on ways to re-configure the text and data to make it more presentable, and finally after 30 minutes reading the TTY-box gem readme I found it had a function that did exactly what we just wasted an afternoon trying to work around. You already installed the gem and required it, might as well take advantage of that!  Be careful though, the more you utilize a gem the more you depend on someone else upkeeping their code.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;My project is available to view on my github &lt;a href="https://github.com/Dane-Dawson/Ruby-Wizard"&gt;here&lt;/a&gt;, feel free to check it out and give some constructive feedback!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Ruby Newby, Classes introduction Part 1</title>
      <dc:creator>Dane Dawson</dc:creator>
      <pubDate>Fri, 14 Feb 2020 18:15:55 +0000</pubDate>
      <link>https://forem.com/danedawson/ruby-newby-classes-introduction-part-1-22d3</link>
      <guid>https://forem.com/danedawson/ruby-newby-classes-introduction-part-1-22d3</guid>
      <description>&lt;p&gt;The object Class is a useful and expansive tool in Ruby programming, but because of the multitude of applications and uses it has in more advanced programming techniques it can be difficult to find a basic and fluid introduction to what they are and how to use them. This will be my attempt at a (hopefully) concise and useful introduction to Classes and their components.&lt;/p&gt;

&lt;p&gt;First let's define what a Class is. In broad terms Class is used as an Object one can use to create objects with defined attributes and methods to interact with those objects. For this article we will think of a Class as a miniature MakerBot full of very basic (and tiny) worker robots. The MakerBot Class can be used to create MakerBot Objects and within the MakerBot class is a place to keep the blueprint for what it makes (these are called attributes and will be covered in more detail in future posts). Unfortunately the workers don't know how to do anything you don't tell them how to do exactly, so there is also a place full of instruction manuals for the workers to follow (these will be the methods we write within the Class itself). Sounds simple enough, right? Let's break it down!&lt;/p&gt;

&lt;p&gt;First, we build our MakerBot (the class):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MakerBot&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's it! We now have a Class called MakerBot. We have to notate that we are making a class, and then name our class. With Ruby you write Class name in CamelCase, combining all words into one line and capitalizing each letter. If our MakerBot was just a factory, for instance, we may name our class Factory. The only downside to our MakerBot as is...it doesn't do anything! Let's give this Class something that happens when you call on it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MakerBot&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;
        &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;"It works!"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Initialize is part of an inhereted method for the Class. Inhereted methods are methods that come with an object inherently, without you having to type any code. An example would be array.length, where length is the inherited method that arrays carry, allowing programmers to discover the length of an array simply by calling length against it. Using initialize and typing (ClassName).new creates an Object (in our case, a MakerBot). The object it makes is defined by whats in the initialize method within the Class, and is where we will be adding in attributes and some specific methods in the future. Right now let's try calling our Class to create a new MakerBot Object.&lt;br&gt;
We can now call our MakerBot by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;MakerBot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and it should return&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;It&lt;/span&gt; &lt;span class="n"&gt;works!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hey look! Our code did something! But having some words on a screen is not really having our own MakerBot...Let me add some lines of code to give it some attributes and really give our MakerBot some substance! Well...digital substance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MakerBot&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can see we added arguments to the initialize method, this will allow us to input values to give our MakerBot some details to make it more like an actual object! Let's try running it now and see what happens...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;MakerBot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Steve"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Waffle-fries"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"The Master Programmer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Huh...that's strange...Nothing happened?  The good news is, you didn't type anything wrong! The problem here is that although we are making a new MakerBot and giving it all these cool attributes, we aren't actually saving anything...anywhere...ever!  On the next post I will continue exploring attributes, and how to save data points in temporary memory. As a teaser, by the end of next lesson the following code will make sense!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MakerBot&lt;/span&gt;
    &lt;span class="ss"&gt;attr_accesor: :name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:product&lt;/span&gt;
    &lt;span class="ss"&gt;attr_reader: :owner&lt;/span&gt;

    &lt;span class="vc"&gt;@@all&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="vi"&gt;@name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;name&lt;/span&gt;
        &lt;span class="vi"&gt;@product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;
        &lt;span class="vi"&gt;@owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;
        &lt;span class="vc"&gt;@@all&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Until next time, happy coding!&lt;/p&gt;

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