<?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: James Shipman</title>
    <description>The latest articles on Forem by James Shipman (@jbshipman).</description>
    <link>https://forem.com/jbshipman</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%2F334309%2F63504cc4-acf6-44b5-bc46-26132af56191.jpeg</url>
      <title>Forem: James Shipman</title>
      <link>https://forem.com/jbshipman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jbshipman"/>
    <language>en</language>
    <item>
      <title>Thoughts on the Past Year and my Career Path Moving Forward</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Sat, 12 Mar 2022 20:18:26 +0000</pubDate>
      <link>https://forem.com/jbshipman/the-past-year-and-where-i-am-going-2g0d</link>
      <guid>https://forem.com/jbshipman/the-past-year-and-where-i-am-going-2g0d</guid>
      <description>&lt;h2&gt;
  
  
  Working From Home
&lt;/h2&gt;

&lt;p&gt;From a coding bootcamp through a year and a half of working at a great company, I've been working from home. This has been a blessing, I moved from a tiny apartment to a lovely home where I feel safe and my family has room to thrive.&lt;/p&gt;

&lt;p&gt;My most natural self needs to interact with people (the extrovert in me) so working from home I've had to figure out new ways of staying focused and "full brained" on the task(s) at hand. My most recent experience has shown me I have space to learn more techniques to up my game and I am using this time between jobs to lean into learning these.&lt;/p&gt;

&lt;h2&gt;
  
  
  DevOps
&lt;/h2&gt;

&lt;p&gt;Where does DevOps fit in this? For me it ties in with the last year and half. I was given an internal project at my previous company to build out CI/CD pipelines. Cool; at the time I didn't even know what that was; little did I know how large of a world was just stepping into. Fast forward roughly 8 months and what I had built had matured into a stable, powerful and adaptable pipeline for website development and deployment. I also feel head over heals this work, it clicked with me like no other work I've done in 15 to 20 years.&lt;/p&gt;

&lt;p&gt;In just the 2 weeks I've been job searching I have had the time to dig deeper into the DevOps universe. I really like and excited about the fact that it's not a highly established, formalized or well-defined practice yet. It's fluid and little different for each company. The overall methodology / philosophy of a collaborative team of different skill sets coming together to work across walls (get rid of them really) to build automated, scalable, testable and adaptable IT solutions is right up my alley. &lt;/p&gt;

&lt;p&gt;This collaborative, cross-functional way of working speaks to me, it calls back to the days that I was in theatre as a performer and as a technician and director. DevOps, to put it simply, is how I've always wanted to work in IT. &lt;/p&gt;

&lt;h2&gt;
  
  
  Let's do This!
&lt;/h2&gt;

&lt;p&gt;So I'm back on the market, looking hard at the roles that focus or want a focus in DevOps processes.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>jobsearch</category>
      <category>career</category>
      <category>workfromhome</category>
    </item>
    <item>
      <title>Post Graduation, week 3 &amp; 4</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Fri, 29 May 2020 21:00:39 +0000</pubDate>
      <link>https://forem.com/jbshipman/post-graduation-week-3-4-1boa</link>
      <guid>https://forem.com/jbshipman/post-graduation-week-3-4-1boa</guid>
      <description>&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;p&gt;So an idea from a friend inspired me to do a "little" side project; I've bulit a template rails api that I (and others) can use to kick start any project. It has a few features that most every web app has nowadays like user authentication, password reset, and soon a basic user profile. It took a lot of work to get it just right, super clean, well documented and what feels to be built with as little code as possible. I have now made it a template repo in my GitHub and it is public; I've given credit where credit is due because very little of this project was only me. Below is the full readme within the repo. I really enjoyed working on this little project; I'm going to continue to build upon it and I hope others will find it helpful as well when starting new personal projects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/jbshipman/template_api"&gt;repo link&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  README
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Template_API
&lt;/h2&gt;

&lt;p&gt;This readme can be used not just a reference for the template but also goes into details for how the user authentication works and why it is configured the way it is. It is very important to note that this all comes from a great youtube series from &lt;a href="https://www.youtube.com/playlist?list=PLgYiyoyNPrv_yNp5Pzsx0A3gQ8-tfg66j"&gt;Edutechnical HTTPS session cookies&lt;/a&gt;. The password reset and emailer functionality is adapted from two blog posts by Pascales Kurniawan, links to the posts are at the bottom of the readme.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Ruby version
&lt;/h3&gt;

&lt;p&gt;2.6.1&lt;/p&gt;

&lt;h3&gt;
  
  
  System defaults
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;localhost port 3001 set within

&lt;ul&gt;
&lt;li&gt;_api/config/initializers/cors.rb-ln7&lt;/li&gt;
&lt;li&gt;_api/config/puma.rb-ln13&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Session Cookies for User Auth
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;CORS setup with broad range of methods, can be customized per application's needs. File can be found here (_api/config/initializers/cors.rb)&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Database initialization
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;rails db:create&lt;/code&gt; is all that is needed to create the initial databases. By default this will create a deveolpment and test database.&lt;/p&gt;

&lt;h3&gt;
  
  
  User Model Configuration
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Used for user authentication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;User Model Creation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails g model User username email password_digest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This generates a User model with a username, email and password; digest works with bcrypt and built in rails functionality to encrypt the string provided as the password.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;strong&gt;user.rb&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="n"&gt;has_secure_password&lt;/span&gt;

  &lt;span class="n"&gt;validates_presence_of&lt;/span&gt; &lt;span class="ss"&gt;:username&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;validates_uniqueness_of&lt;/span&gt; &lt;span class="ss"&gt;:username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:email&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_password_token!&lt;/span&gt;
    &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reset_password_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;generate_token&lt;/span&gt;
    &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reset_password_sent_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utc&lt;/span&gt;
    &lt;span class="n"&gt;save!&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;password_token_valid?&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reset_password_sent_at&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hours&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utc&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;reset_password!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reset_password_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;
    &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;
    &lt;span class="n"&gt;save!&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="kp"&gt;private&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_token&lt;/span&gt;
    &lt;span class="no"&gt;SecureRandom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&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;Default configuration is to enforce a unique username and email for each user that registers. Password tokens are generated as a random hex number 16 characters long; and a timestamp is created at the time of generation. That timestamp is used to compare against when the password is reset to ensure a timeframe inwhich the token is valid; in this template it is set to a 4 hour window but that can be changed.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;current_user_concern.rb&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This module creates a before action to be used universally that sets the current user to the user stored in sessions; allowing front-end pages to check the current user when needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="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;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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;sessions_controller.rb&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Controlls user session creation, logging in and logging out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="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="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;username: &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;"username"&lt;/span&gt;&lt;span class="p"&gt;])&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="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;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="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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;registrations_controller.rb&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Handles the creation of a user account and wraps the json object in a user key. The json string for a user will look like the following. &lt;code&gt;{"user":{"username":"", "email":"", "password":"", "password_confirmation":""}}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="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;create!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="ss"&gt;username: &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;"username"&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="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="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="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="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&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;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;user: &lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  API Endpoints / Routes
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;routes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Routes for forgotten password&lt;/span&gt;
  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s2"&gt;"password/forgot"&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;"passwords#forgot"&lt;/span&gt;
  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s2"&gt;"password/reset"&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;"passwords#reset"&lt;/span&gt;

  &lt;span class="c1"&gt;# Create a User session&lt;/span&gt;
  &lt;span class="c1"&gt;# Create a new User via registration&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="c1"&gt;# Log a user out&lt;/span&gt;
  &lt;span class="c1"&gt;# Check to make sure a user is logged in&lt;/span&gt;
  &lt;span class="c1"&gt;# this is used when moving in the app&lt;/span&gt;
  &lt;span class="c1"&gt;# to check the user remains logged in&lt;/span&gt;
  &lt;span class="n"&gt;delete&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="c1"&gt;# Static page at root of api to make sure&lt;/span&gt;
  &lt;span class="c1"&gt;# server is running&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;static_controller.rb&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Render json status at server root for basic checking of function - i.e. is the server running.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;strong&gt;application_controller.rb&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;...&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="o"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Makes sure authentication token is verified before anything else.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Forgotten password
&lt;/h3&gt;

&lt;p&gt;Two posts from Pascales Kurniawan are my sources that helped me build a password reset process including send out emails for a welcome, password reset and a reset confirmation.&lt;/p&gt;

&lt;p&gt;It starts with creating a passwords controller, there's a lot here but we will go through it all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;passwords_controller.rb&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;forgot&lt;/span&gt;
    &lt;span class="c1"&gt;# check first if email exists, neede d because&lt;/span&gt;
    &lt;span class="c1"&gt;# though email is required to register, non-templated app&lt;/span&gt;
    &lt;span class="c1"&gt;# may allow for email to be removed by user later&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:username&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;blank?&lt;/span&gt;
      &lt;span class="k"&gt;return&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;error: &lt;/span&gt;&lt;span class="s2"&gt;"Username not present"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="c1"&gt;# find user by email&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;username: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:username&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;# if present then generate a token&lt;/span&gt;
    &lt;span class="k"&gt;if&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;present?&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;generate_password_token!&lt;/span&gt;

      &lt;span class="c1"&gt;# send out email&lt;/span&gt;
      &lt;span class="no"&gt;UserMailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forgot_password&lt;/span&gt;&lt;span class="p"&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;deliver_now&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;"ok"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;status: :ok&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;error: &lt;/span&gt;&lt;span class="s2"&gt;"Email address not found. Please check and try again."&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;status: :not_found&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;reset&lt;/span&gt;
    &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:token&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;to_s&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:email&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;blank?&lt;/span&gt;
      &lt;span class="k"&gt;return&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;error: &lt;/span&gt;&lt;span class="s2"&gt;"Token not present"&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;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;reset_password_token: &lt;/span&gt;&lt;span class="n"&gt;token&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;if&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;present?&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&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;password_token_valid?&lt;/span&gt;
      &lt;span class="k"&gt;if&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;reset_password!&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="ss"&gt;:password&lt;/span&gt;&lt;span class="p"&gt;])&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;"ok"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;status: :ok&lt;/span&gt;

        &lt;span class="c1"&gt;# send email&lt;/span&gt;
        &lt;span class="no"&gt;UserMailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;password_reset&lt;/span&gt;&lt;span class="p"&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;deliver_now&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;error: &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;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;full_messages&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;status: :unprocessable_entity&lt;/span&gt;
      &lt;span class="k"&gt;end&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;error: &lt;/span&gt;&lt;span class="s2"&gt;"Link not valid or expired. Try generating a new link."&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;status: :not_found&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 &lt;code&gt;forgot&lt;/code&gt; method starts by checking if the username params is blank or not. There are no views setup in this api, but this covers a use case of leaving the username field blank but still clicking on a submit button.&lt;/p&gt;

&lt;p&gt;If the username is found then a password toekn is generated - that method is in the user model - and send an email. Email will be covered later. Finally if the user does not have an email on record then an error is passed forward. This is also an anticapated failsafe, but not one that is needed as is for the template. This is because email is required in the template api, a new user won't be created without one.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;reset&lt;/code&gt; method functions very similar to the &lt;code&gt;forgot&lt;/code&gt; method. This first takes the token that is sent in the email (more on this later) and takes it back as a param. If the email is blank (again, from frontend params, no views are created but the checks are in place) then it passes an error.&lt;/p&gt;

&lt;p&gt;A check for both a present user &lt;em&gt;and&lt;/em&gt; a valid token allows the password to be reset from a given param and then send an email confirming the email has been changed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Emails
&lt;/h3&gt;

&lt;p&gt;To send emails from a rails backend you start by creating a mailer like a controller.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g mailer UserMailer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;_api/app/mailers/application_mailer.rb&lt;/code&gt; file there is a change to be made. This is one of the places that follow that will not work right out of the box in this api. I tested everything with an email setup I created for myself and removed that information. It's a simple process of creating a new gmail account that can be used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;application_mailer.rb&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="n"&gt;default&lt;/span&gt; &lt;span class="ss"&gt;from: &lt;/span&gt;&lt;span class="s2"&gt;"create-a-new-email@gmail.com"&lt;/span&gt;
  &lt;span class="n"&gt;layout&lt;/span&gt; &lt;span class="s2"&gt;"mailer"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets start with what needs to be configured in &lt;code&gt;_api/config/environments/development.rb&lt;/code&gt;. Add the below to the file; this configures the development environment for gmail and sending emails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;development.rb&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Don't care if the mailer can't send.&lt;/span&gt;
  &lt;span class="c1"&gt;# Comment out the below as it is used again&lt;/span&gt;
  &lt;span class="c1"&gt;# if email is not needed in your app uncomment this one&lt;/span&gt;
  &lt;span class="c1"&gt;# config.action_mailer.raise_delivery_errors = false&lt;/span&gt;

  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;action_mailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perform_caching&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;

  &lt;span class="c1"&gt;# configuration for sending out welcome email from Gmail&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;action_mailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delivery_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;:sendmail&lt;/span&gt;
  &lt;span class="c1"&gt;# config.action_mailer.delivery_method = :test&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;action_mailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;default_url_options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;:host&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"http://localhost:3001/password/reset"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;action_mailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perform_deliveries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;action_mailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_delivery_errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;action_mailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;default_options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;from: &lt;/span&gt;&lt;span class="s2"&gt;"create-a-new-email@gmail.com"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;action_mailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delivery_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;:smtp&lt;/span&gt;
  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;action_mailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;smtp_settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="ss"&gt;address: &lt;/span&gt;&lt;span class="s2"&gt;"smtp.gmail.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;port: &lt;/span&gt;&lt;span class="mi"&gt;587&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;"gmail.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;user_name: &lt;/span&gt;&lt;span class="s2"&gt;"create-a-new-email@gmail.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;password: &lt;/span&gt;&lt;span class="s2"&gt;"password"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;authentication: &lt;/span&gt;&lt;span class="s2"&gt;"plain"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;enable_starttls_auto: &lt;/span&gt;&lt;span class="kp"&gt;true&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;&lt;strong&gt;email views&lt;/strong&gt;&lt;br&gt;
These are simple &lt;code&gt;html.erb&lt;/code&gt; files and &lt;code&gt;text.erb&lt;/code&gt; files. They are all in the user_mailer folder within the views folder of the rails app. There is a view that corresponds with each method in the &lt;code&gt;_api/app/mailers/user_mailer.rb&lt;/code&gt; file. Those methods create the email header; the views files create the email body.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;forgot_password.html.erb&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Forgot your password&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;
  Don't worry about it, this happens to us all from time to time.&amp;lt;br /&amp;gt;
  Your username on record is: &amp;lt;%= @user.username %&amp;gt;&amp;lt;br /&amp;gt;
  Your email on record is: &amp;lt;%= @user.email%&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;
  Follow this link to create a new password &amp;lt;%= link_to "Reset Your Password",
  ('http://localhost:3001/password/reset?token='+@user.reset_password_token) %&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;
  This link will only work once and is only valid for the next 4 hours; so get
  to it. &amp;lt;br /&amp;gt;
  Cheers!
&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This specific view is important because it shows how to embed the reset token into the link back to server so the user never has to see or interact with the token.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;

&lt;p&gt;The only steps needed to deploy this template api are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;fork the repo in GitHub&lt;/li&gt;
&lt;li&gt;clone it to your local system - allow the template to be the root of your backend, you can rename it as needed&lt;/li&gt;
&lt;li&gt;run &lt;code&gt;bundle&lt;/code&gt; from api root&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is it. The api is set and ready to go. You can start up the server and test the functionality after you update smtp settings to an email you want to test with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Sessions Testing
&lt;/h3&gt;

&lt;p&gt;In Terminal,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start rails server (per template config it will run on port 3001)&lt;/li&gt;
&lt;li&gt;New Terminal Tab type the following:
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;It is just easier to type this in Terminal than to try to test api with an application like Postman or Insomnia. The backslash is just to allow multiple lines in Terminal.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Server response if configuration is correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"status":"created",
"logged_in":true,
"user":{"id":1,"username":"ronkilav","email":"ronkilav@email.com",
"password_digest":"$2a$12$Fj6ZBybAM15mNdQYeuSzceiKXwH5Knl0VTNmfuU9BxQzyY9yBnncK",
"created_at":"2020-05-19T20:45:58.288Z",
"updated_at":"2020-05-19T20:45:58.288Z"}}
[16:06:22]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Output is actually on a single line, I placed it on multiple lines for readablity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Forgotten Password Testing
&lt;/h3&gt;

&lt;p&gt;To test the process for reseting a password (and the emailing functionality) use a program like insomnia or postman; or modify the above curl command that checks if there is a user stored in sessions.&lt;/p&gt;

&lt;p&gt;For password reset test I used insomnia and will include screenshots of the three POST requests needed for full testing.&lt;/p&gt;

&lt;p&gt;To test the full process start by creating a new user. This can be done in a rails console but doing so will bypass the &lt;code&gt;registrations_controller.rb&lt;/code&gt; and therefore the email process. So in insomnia create a POST request with all the needed new user information.&lt;/p&gt;

&lt;p&gt;As long as you setup the email services first before these tests then you will get an email after registering a new user, requesting a new password and after setting a new password.&lt;/p&gt;

&lt;p&gt;You will need rails console to get the reset token to add to the reset post request, but with a frontend or a set of views built out it will pass that token along as needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links and resources
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;italic bullet points to be made after forking this template&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;a href="https://github.com/jbshipman/template_api"&gt;GitHub Repo&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href=""&gt;Design Docs&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href=""&gt;ERModel link&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href=""&gt;Project Blog&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;a href=""&gt;Project Demo&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/playlist?list=PLgYiyoyNPrv_yNp5Pzsx0A3gQ8-tfg66j"&gt;Edutechnical HTTPS session cookies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/binar-academy/forgot-password-feature-on-rails-api-8e4a7368c59"&gt;Password Reset&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@pascales/welcome-email-for-new-user-using-action-mailer-becdb43ee6a"&gt;Sending Email&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>jobsearch</category>
      <category>career</category>
      <category>productivity</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Post Graduation, week 2</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Tue, 19 May 2020 21:43:32 +0000</pubDate>
      <link>https://forem.com/jbshipman/post-graduation-week-2-5735</link>
      <guid>https://forem.com/jbshipman/post-graduation-week-2-5735</guid>
      <description>&lt;p&gt;&lt;em&gt;cover image credit &lt;a href="https://thumbs.dreamstime.com/z/job-search-concept-chart-keywords-icons-gray-background-job-search-concept-chart-keywords-icons-gray-102351681.jpg"&gt;image url&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;p&gt;I have been doing lots of company research to find a small handful of organizations I want to / would love to work for. This includes seeing if these specific companies have openings for a Junior Software Engineer. If they do, fantastic; if not then I am still doing the research.&lt;/p&gt;

&lt;p&gt;I am also brainstorming ideas for my next project and I think I figured out what I want to build. I have spent a number of nights now on paper toying around with needed algorithms and logic to make my idea work. Have to say I am very fasinated by Sudoku and it is so much more complex to implement a game then I thought it would be; it's a challenge I want to take on.&lt;/p&gt;

&lt;h1&gt;
  
  
  What has been happening this week
&lt;/h1&gt;

</description>
      <category>jobsearch</category>
      <category>career</category>
      <category>productivity</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Post Graduation, week 1</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Tue, 12 May 2020 23:02:20 +0000</pubDate>
      <link>https://forem.com/jbshipman/post-graduation-week-1-1blg</link>
      <guid>https://forem.com/jbshipman/post-graduation-week-1-1blg</guid>
      <description>&lt;p&gt;&lt;em&gt;cover image credit &lt;a href="https://thumbs.dreamstime.com/z/job-search-concept-chart-keywords-icons-gray-background-job-search-concept-chart-keywords-icons-gray-102351681.jpg"&gt;image url&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Intro
&lt;/h1&gt;

&lt;p&gt;Let's not beat around the bush here, nobody likes the job hunting process (or almost nobody, I'm not a Sith so I should stay away from absolutes). After 15 weeks of an intense software engineering bootcamp I am now master of my own schedule again. This is good, and to be honest, potentially bad.&lt;/p&gt;

&lt;p&gt;The motivation to land my first software engineering role is extremely high; so is the anxiety regarding the pandemic and what that reality is doing to the job market. So what is a new S.E. in the market for his first role to do? Roll up his sleeves and focus only on the task in front of me. Or, more precisely, tasks in front of me.&lt;/p&gt;

&lt;h1&gt;
  
  
  All the Things
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;I have an online pressence to update to ensure it is all consistent and stating I am looking for my first role.&lt;/li&gt;
&lt;li&gt;I have a resume that needs to be retooled from my past as an IT Manager and Project Manager to Software Enineer noob with a lot of drive.&lt;/li&gt;
&lt;li&gt;There are project demos to record.&lt;/li&gt;
&lt;li&gt;A portfolio site to conceive and create as well as brainstorm future projects to work on to add to my portfolio.&lt;/li&gt;
&lt;li&gt;A dog to walk often.&lt;/li&gt;
&lt;li&gt;An apartment to keep livable.&lt;/li&gt;
&lt;li&gt;My personal health to maintain.&lt;/li&gt;
&lt;li&gt;A kiddo that needs her Dad.&lt;/li&gt;
&lt;li&gt;A social life (thank you Covid, jerk) for mental health.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is a lot and I am not in any way saying that it is more than anyone else; but it is mine and there you go.&lt;/p&gt;

&lt;h1&gt;
  
  
  Wordy bits
&lt;/h1&gt;

&lt;p&gt;So what to do about all of this? First, keep a schedule. Wake up at the same time each day, go to bed at the same time each day. Make sure I have a group of friends and/or collegues that are willing to be my check and balance and I to be that for them. A close friend coined the term Accountabilibuddies; and I love it (thank you &lt;a href="https://dev.to/danedawson"&gt;Dane Dawson&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;For myself, this new blog series is going to be part of my routine. Each week I will post about my journey between coding bootcamp and landing my first job. This week is preparation. As the list above indicates, I have a lot of prep work to do: Resume, LinkedIn, etc.&lt;/p&gt;

&lt;p&gt;Writing about myself is not easy. The mental wall I hit each time I try to come up with a different/better way of discussing my career up to now is a little daunting, just because it's hard doesn't mean it's impossible.&lt;/p&gt;

&lt;p&gt;So far the most helpful and motivational things that has happened since graduation is a group of us from class have created a group on a site called &lt;a href="https://habitica.com/"&gt;habitica&lt;/a&gt;. It gamifies tasks and habits. Getting a digital pet for completing the things I need to get done in order to land a job is awesome - silly - but awesome.&lt;/p&gt;

&lt;h1&gt;
  
  
  Portfolio Site
&lt;/h1&gt;

&lt;p&gt;Research, research, research. I don't know what I want my portfolio site to look like. I know the goals of the site, I know what the basic semantic structure of the site should be. Everything else, work in progress. So I scour the internet for other software engineer portfolio sites to get ideas. My favorite, so far, is the portfolio site for &lt;a href="https://brittanychiang.com"&gt;Brittnay Chiang&lt;/a&gt;. I don't yet have enough projects to showcase to make this type of site layout and flow work for me, but this is a good candidate for a version 2 or 3 down the road.&lt;/p&gt;

&lt;p&gt;So I will continue to brainstorm. I use MindNode to capture my thoughts and brainstorm ideas; I'm visual in my thinking and a mindmap lends itself really nicely to my way of thinking through things. Here is the &lt;a href="https://my.mindnode.com/LxGswkB8tqQ2wDgRuRL8xfqScxWx5umWKWFDc8YT#73.7,39.0,2"&gt;link&lt;/a&gt;, should you want to have a glance at my thoughts (it's not a scary as it seems, I tell myself).&lt;/p&gt;

&lt;h1&gt;
  
  
  Projects to Keep my Skills Sharp
&lt;/h1&gt;

&lt;p&gt;So in addition to spinning up a portfolio site, I also need and want to work on new projects. I've put a few idea down and continue to add to a &lt;a href="https://my.mindnode.com/x6Gyae2ypC3VoWkfrMksQdfRdDr9fxCGyW4D6jJz"&gt;brainstorm map&lt;/a&gt;. I'm sharing that one as well because I really like the idea of everything I build out on my own time being completely Open Source and my personal work process being open and transparent too.&lt;/p&gt;

&lt;h1&gt;
  
  
  This is a Long Blog
&lt;/h1&gt;

&lt;p&gt;All right, I've written a lot, if you're down here you've read a lot. Thank you for thank &amp;lt;3&lt;/p&gt;

&lt;p&gt;Cheers! and you'll catch me in my next post.&lt;/p&gt;

</description>
      <category>jobsearch</category>
      <category>career</category>
      <category>productivity</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Final Project - User Profile</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Wed, 29 Apr 2020 20:05:33 +0000</pubDate>
      <link>https://forem.com/jbshipman/final-project-user-profile-440i</link>
      <guid>https://forem.com/jbshipman/final-project-user-profile-440i</guid>
      <description>&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;So, yeah. This took a lot longer than I anticipated it would because I over estimated how much I understood and remembered about basic CRUD functionality in rails and how react ties into it all. I am not going to belabor the point by talking each line of code here but I will post it all, along with the notes I took to keep track of what it was all doing.&lt;/p&gt;

&lt;h1&gt;
  
  
  Rails model, controller and route
&lt;/h1&gt;

&lt;p&gt;There are so many ways one can build a user profile. Make it part of the user model, keep it separate (I did the separate model), will the profile have unique information that only associates to a user or will it also contain information from elsewhere in the app/database/3 rd party data pulled in ....? I choose to make it a 1:1 association that does not contain any non user information. Basically I could have put all the same columns into the user model. Keeping them separate but associated made it easier for me (or I thought it was going to) to build the routes and needed CRUD functionality.&lt;/p&gt;

&lt;p&gt;The first issue I came across with the profile was that before a user created a profile there was nothing for the profile component to display and that gave me errors. Ultimately it was decided (myself and instructors) that when a new user was registered that the controller would also make an associated profile record with default data ("first name", "last name" that kinda stuff), in order for the profile page to have something to render. While this solved many problems what it caused was a rabbit hole of issues getting an Update route to work in a way that I understood and could replicate for future models/features in the app.&lt;/p&gt;

&lt;p&gt;Here is what I finally got to work. For any one reading this more experienced than myself (that would be all of you FYI), please feel free to blast my potential "code smell", and non DRY-ness .... I am a dev noob, here me type way too much ;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;profiles_controller.rb&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProfilesController&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;show&lt;/span&gt;
    &lt;span class="n"&gt;profile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Profile&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;id: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;json: &lt;/span&gt;&lt;span class="n"&gt;profile&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;update&lt;/span&gt;
    &lt;span class="c1"&gt;# grab current_user id to build a profile onto&lt;/span&gt;
    &lt;span class="c1"&gt;# try is built in&lt;/span&gt;
    &lt;span class="c1"&gt;# {profile: {firstname, lastname, ....}}&lt;/span&gt;
    &lt;span class="n"&gt;profile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Profile&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;id: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="ss"&gt;firstname: &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;"profile"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;"firstname"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="ss"&gt;lastname: &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;"profile"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;"lastname"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="ss"&gt;bio: &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;"profile"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;"bio"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="ss"&gt;birthday: &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;"profile"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;"birthday"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="c1"&gt;# user_id: @current_user.id,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# conditional to render json object of a status notification, a boolean for logged in, and the user model data&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;profile&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="vi"&gt;@current_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: :updated&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="ss"&gt;profile: &lt;/span&gt;&lt;span class="vi"&gt;@current_profile&lt;/span&gt;&lt;span class="p"&gt;,&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;blockquote&gt;
&lt;p&gt;not sure if the &lt;code&gt;show&lt;/code&gt; method needs to be there, but it's staying in because everything in my app to this point is working. I took a lot of similar code from the registrations controller as that controller creates a user, so the I figured they would have similar structure and such.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Next is the routes for the profile.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;routes.rb&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="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="ss"&gt;:update&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;delete&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="c1"&gt;# update :update, to: "sessions#update"&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;:profiles&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;:show&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:update&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;# resources :users, only: [:show] do&lt;/span&gt;
  &lt;span class="c1"&gt;# end&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;blockquote&gt;
&lt;p&gt;I ultimately decided on not nesting the profile update route in the user route because the user routes aren't needed; the user "stuff" is handled in sessions and registrations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Over in React land, the component I created for updating the profile (UpdateProfile, I know ... surprise naming convention). The part that gave me the most challenge was the part where I had to actually update the backend from the frontend. Here is the function in its working form that patches the profile record correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;UpdateProfile.js&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="nf"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// console.log(e.target.value);&lt;/span&gt;
    &lt;span class="c1"&gt;// const { firstname, lastname, bio, birthday } = this.setState;&lt;/span&gt;
    &lt;span class="c1"&gt;// const uId = this.props.user.id;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// console.log(this.state);&lt;/span&gt;

    &lt;span class="nx"&gt;axios&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="c1"&gt;// "http://localhost:3001/profiles",&lt;/span&gt;
        &lt;span class="s2"&gt;`http://localhost:3001/profiles/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;pId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;profile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;firstname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;lastname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;bio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bio&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;birthday&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthday&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="c1"&gt;// user_id: this.props.user.id,&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;span class="na"&gt;withCredentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// console.log(this.state);&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;updated&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;profile has been updated&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;handleShowUpdateProfile&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
          &lt;span class="c1"&gt;// this.props.handleSuccessfullAuth(resp.data);&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;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;update error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;// alert("update error", error);&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// event.preventDefault();&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;blockquote&gt;
&lt;p&gt;Getting the correct match up of data structure between the frontend and the backend was tricky as I seem to mis bad spelling and transposed characters really, really easily. This gets the job done just fine though.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The function &lt;code&gt;this.props.handleShowUpdateProfile()&lt;/code&gt; is passed down from the parent component that holds both &lt;code&gt;UpdateProfile&lt;/code&gt; and &lt;code&gt;Profile&lt;/code&gt; components. I have &lt;code&gt;UpdateProfile&lt;/code&gt; rendering in a conditional statement based on a boolean state. This ensures that the &lt;code&gt;UpdateProfile&lt;/code&gt; component - which is just a form - is hidden upon correct saving of data back to the controller - that's the &lt;code&gt;if (resp.data.status ......)&lt;/code&gt; portion of the promise. I really like how placing a conditional based on a status that is sent from the backend you can kind of force the an order of operation to what is actually async behavior. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;I take no credit for this, the video series I watched that helped me build the user authentication system used this, so I stole it like a good programmer&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Note taking and Keeping Track of What the Flip is Going on in my App
&lt;/h1&gt;

&lt;p&gt;To say I got lost in the logic and data flow of my the little app that I have is an understatement. Just the user authentication was a knot I had to untie each time I sat down to work. It got to the point that I had to find a way to write down how it worked. Not the code itself, that's took hairy to look at and I'm a visual thinker so words are hard. I found myself tell VSCode many times that I wish it would draw me a map of what functions live in what component, where the states are being passed down from, which component is nested where ..... so I did that. I have easily spent half as much time taking note of all of this as I have actually writing code and troubleshooting code.&lt;/p&gt;

&lt;p&gt;Here is what I came up with, and for anyone else that is a visual thinker like me I hope you find this helpful. I used mind mapping to build out the flow of the data, how the components connect and the logic of different aspects of the app. It doesn't matter the specific app I used as I'm not here to promote one useful app over another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Component Tree&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fux0cf2s33knsy3r2rdph.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fux0cf2s33knsy3r2rdph.png" alt="Component Tree" width="800" height="646"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Frontend Logic&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faqnp9pnew383j4yjf9jt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faqnp9pnew383j4yjf9jt.png" alt="Frontend Logic" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is a link to the full mind map, the above are just screen grabs of specific portions of the larger map. &lt;br&gt;
&lt;a href="https://my.mindnode.com/njyMtZp4j4WydrpHks6vsbMTpCxmjWPX2vXf2xm4"&gt;Mind map&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading this post, it was a longer one. Future posts on this project will hopefully be shorter.&lt;/p&gt;

&lt;p&gt;Stay healthy :)&lt;/p&gt;

</description>
      <category>rails</category>
      <category>react</category>
    </item>
    <item>
      <title>Final Project - User Model</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Sun, 26 Apr 2020 14:15:57 +0000</pubDate>
      <link>https://forem.com/jbshipman/final-project-user-model-3h6i</link>
      <guid>https://forem.com/jbshipman/final-project-user-model-3h6i</guid>
      <description>&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;I create my User model and build out the base of the needed Sessions controller.&lt;/p&gt;

&lt;h1&gt;
  
  
  User Model
&lt;/h1&gt;

&lt;p&gt;My app will have a separate Profile model that will contain most of a User's info (bio, profile pic, birthday, etc).&lt;/p&gt;

&lt;p&gt;So for my User model I just need the following&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;username&lt;/li&gt;
&lt;li&gt;email&lt;/li&gt;
&lt;li&gt;password&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because I am using bcrypt and not JWT or any other complicated - and still not a system I understand how to use - the &lt;code&gt;password&lt;/code&gt; field needs to be create with &lt;code&gt;_digest&lt;/code&gt;. Here is the command I wrote to generate the User model.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails g model User username email password_digest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It generated this file &lt;code&gt;001_create_users.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreateUsers&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Migration&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;6.0&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;change&lt;/span&gt;
    &lt;span class="n"&gt;create_table&lt;/span&gt; &lt;span class="ss"&gt;:users&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:username&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:email&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:password_digest&lt;/span&gt;

      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timestamps&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;blockquote&gt;
&lt;p&gt;Before I migrated I checked the migration file to ensure I typed things correctly. I also renamed the mirgration file, taking the datatime out of the file name and replacing it with &lt;code&gt;001&lt;/code&gt;. This is a little thing I've picked up durning my time in this bootcamp that I find to be helpful if there are going to be a few migration files. Numbering them like this allows for easier troubleshooting - for me at least - if something goes wrong with a model at some point. I can look at the schema file and see what version it is on (4, maybe 8) instead of a version number twelve characters long. Also easier to rollback a specific migration if needed by typing 00x instead of 2020xxyyzzww .... blah blah blah.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I digress.&lt;/p&gt;

&lt;p&gt;With the model migrated go to the &lt;code&gt;user.rb&lt;/code&gt; model and include the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;has_secure_password&lt;/span&gt; 
&lt;span class="c1"&gt;# part of bycrpt&lt;/span&gt;
&lt;span class="c1"&gt;# needed to ensure the &lt;/span&gt;
&lt;span class="c1"&gt;# password is not saved as plain text&lt;/span&gt;

&lt;span class="c1"&gt;# below are nice to have but not required&lt;/span&gt;
&lt;span class="c1"&gt;# I want my app to ensure usernames and emails are unique&lt;/span&gt;
&lt;span class="c1"&gt;# it gives me more options for searching and finding users later&lt;/span&gt;
&lt;span class="n"&gt;validates_presence_of&lt;/span&gt; &lt;span class="ss"&gt;:username&lt;/span&gt;
&lt;span class="n"&gt;validates_uniqueness_of&lt;/span&gt; &lt;span class="ss"&gt;:username&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="n"&gt;validates_uniqueness_of&lt;/span&gt; &lt;span class="ss"&gt;:email&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Sessions Controller
&lt;/h1&gt;

&lt;p&gt;So the full details on exactly what a session is and what the controller is/does is not fully understood by me as of yet... &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;(fyi, it is April 26th 2020, for future readers and myself)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;... but full understanding isn't needed right now. I get what the code is doing in general terms and for only 13 weeks into learning to be a software engineer; I'd say I'm doing okay in the understand a lot of stuff department.&lt;/p&gt;

&lt;p&gt;Here is what needs to go into a Sessions Controller to get the base authentication functionality in place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="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="c1"&gt;# find user by uniq username&lt;/span&gt;
    &lt;span class="c1"&gt;# try is built in&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;username: &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;"username"&lt;/span&gt;&lt;span class="p"&gt;])&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="c1"&gt;# conditional to render json object of a status notification, &lt;/span&gt;
    &lt;span class="c1"&gt;# a boolean for logged in, and the user model data&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="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; 
      &lt;span class="c1"&gt;# if something goes wrong, a username isn't found, &lt;/span&gt;
      &lt;span class="c1"&gt;# hacker doing hacky things, 401 is the standard status code&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;



</description>
      <category>rails</category>
      <category>authentication</category>
    </item>
    <item>
      <title>Final Project - rails backend initalization</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Sat, 25 Apr 2020 22:25:14 +0000</pubDate>
      <link>https://forem.com/jbshipman/final-project-4c53</link>
      <guid>https://forem.com/jbshipman/final-project-4c53</guid>
      <description>&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;So I want to begin by saying this has been the most dificult aspect of bootcamp thus far; user authentication. It's a deep subject, it's dense and it really tested how much I had learned in such a short amount of time. That being said, I finally found a great tutorial series that explained it beautifully. Edutechional's React + Rails API Authentication video series. Here's the link, check it out, it's amazing and helped me finally grasp the basics of this concept. Here's the link to the series on youtube: &lt;a href="https://www.youtube.com/playlist?list=PLgYiyoyNPrv_yNp5Pzsx0A3gQ8-tfg66j"&gt;https://www.youtube.com/playlist?list=PLgYiyoyNPrv_yNp5Pzsx0A3gQ8-tfg66j&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay so this post will be a summary of what I learned and act as a reference guide for myself for future projects, and hopefully will be a guide for someone else as well.&lt;/p&gt;

&lt;h1&gt;
  
  
  Rails as the backend
&lt;/h1&gt;

&lt;p&gt;Though rails has an &lt;code&gt;-api&lt;/code&gt; only way of creation, the above mentioned series and a few other sources as well in fact, it seems to me that a decent number of devs out there find it is easier to implement an api build when it's not just and api build. Something to do with dependancies and things that are beyond the scope of this blog (and my understanding at the time of writing this blog frankly).&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: create the rails app
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;I will do my best to make note of where names are specific to my applicaiton and what things are needed as is for the build to work.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# rails new &amp;lt;app_name_here&amp;gt; --database=postgresql&lt;/span&gt;
&lt;span class="n"&gt;rails&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;familicule_api&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;postgresql&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gets the ball rolling on things and may take a moment or two depending on your system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: gems
&lt;/h2&gt;

&lt;p&gt;I like awesome print, a lot. It makes looking at rails database information, routes, and methods a lot easier, so I have been adding it to all my rails projects as of late.&lt;/p&gt;

&lt;p&gt;It easy to do, just open the &lt;code&gt;Gemfile&lt;/code&gt; and add &lt;code&gt;gem 'awesome_print', '~&amp;gt; 1.8'&lt;/code&gt;. I tend to add it at the top below &lt;code&gt;ruby '2.6.1&lt;/code&gt; but I don't think the location of it is super important as long as it's not placed within the &lt;code&gt;group: .....&lt;/code&gt; sections&lt;/p&gt;

&lt;p&gt;The other item that needs to be added to the &lt;code&gt;Gemfile&lt;/code&gt; is CORS. This gem does a lot of things, most of which are still a mystery to me. I've added &lt;code&gt;gem 'rack-cors', :require =&amp;gt; 'rack/cors'&lt;/code&gt; at the bottom of the &lt;code&gt;Gemfile&lt;/code&gt; -- again, not sure if it really is important where these go; please comment if you do.&lt;/p&gt;

&lt;p&gt;Finally, &lt;code&gt;bcrypt&lt;/code&gt;. Lets make sure it's going to bundle install the latest version &lt;code&gt;gem 'bcrypt', '~&amp;gt; 3.1', '&amp;gt;= 3.1.12'&lt;/code&gt; update to that and all should be good.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: CORS and Sessions
&lt;/h2&gt;

&lt;p&gt;Create a cors file that allows for locahost for now but later we will need to also allow deployment server(s)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="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="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="s1"&gt;'http://localhost:3000'&lt;/span&gt;
    &lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s1"&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;# allow do&lt;/span&gt;
  &lt;span class="c1"&gt;#   origins 'https://api.herokuapp.com' &lt;/span&gt;
  &lt;span class="c1"&gt;#   resource '*', headers: :any, methods: [:get, :post, :put, :patch, :delete, :options, :head], credentials: true&lt;/span&gt;
  &lt;span class="c1"&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;Session Store is another initalizer which defines what the cookie is going to be called on a local system and the domain the cookie is tied to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="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="s1"&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="s1"&gt;'_familicule_app'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;domain: &lt;/span&gt;&lt;span class="s1"&gt;'familicule-api.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="s1"&gt;'_familicule_app'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Skipping ahead a little; the conditional allows for a localhost for testing and a deployed domain for deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Basic route and controller
&lt;/h2&gt;

&lt;p&gt;The last two files to create so that we can test that this rails app can be spun up are a route in the &lt;code&gt;routes.rb&lt;/code&gt; file and a controller called &lt;code&gt;static_controller.rb&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;routes.rb&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This creates a route for the browser to look at a controller called &lt;code&gt;static&lt;/code&gt; at it's root level.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;code&gt;static_controller.rb&lt;/code&gt; will one &lt;code&gt;def&lt;/code&gt;, home (to match the &lt;code&gt;static#home&lt;/code&gt; in the &lt;code&gt;routes.rb&lt;/code&gt; file).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="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;p&gt;Spin up the rails server &lt;code&gt;rails s -p 3001&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: I spin the rails server up on port 3001 so it won't conflict with the react server later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to &lt;code&gt;localhost:3001&lt;/code&gt; in your browser and you'll be greeted by a simple rendered json object. &lt;code&gt;{"status":"It's working"}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;At this point it's a great time to initialize this backend into github. I won't cover that little step here in this blog (maybe a furture blog), but this will make a perfect master branch. All future steps are in upcoming blog posts - I'm doing this so that this guide isn't a mile long.&lt;/p&gt;

</description>
      <category>rails</category>
    </item>
    <item>
      <title>Final Project - the beginning</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Tue, 21 Apr 2020 17:53:53 +0000</pubDate>
      <link>https://forem.com/jbshipman/final-project-the-beginning-1537</link>
      <guid>https://forem.com/jbshipman/final-project-the-beginning-1537</guid>
      <description>&lt;h1&gt;
  
  
  The End is Near
&lt;/h1&gt;

&lt;p&gt;Well, it's here; the final 3 weeks of my code bootcamp journey. I've made some amazing friendships, crammed a metric ton of information into my - sometimes unwilling - brain; and I am confident that I have what it takes to be a sucessful software engineer.&lt;/p&gt;

&lt;p&gt;Over the next 3 weeks I plan on posting micro-blogs of my progress and journey on this final project.&lt;/p&gt;

&lt;p&gt;So lets get this blog series started with this little post and I'll have more everyother day (that's my plan as of now at least).&lt;/p&gt;

&lt;p&gt;Enjoy the read, ping me with questions or comments as this series continues and stay healthy all :)&lt;/p&gt;

</description>
      <category>rails</category>
      <category>react</category>
    </item>
    <item>
      <title>JavaScript ... love it or hate it, here's how to use it</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Thu, 19 Mar 2020 17:49:57 +0000</pubDate>
      <link>https://forem.com/jbshipman/javascript-love-it-or-hate-it-here-s-how-to-use-it-1kem</link>
      <guid>https://forem.com/jbshipman/javascript-love-it-or-hate-it-here-s-how-to-use-it-1kem</guid>
      <description>&lt;h1&gt;
  
  
  JavaScript
&lt;/h1&gt;

&lt;p&gt;Ahhh JavaScript, the little DOM language that grew into a monster/beast/foundational web technical ... take your pick of terms.&lt;/p&gt;

&lt;p&gt;It's light-weight, it &lt;em&gt;can be&lt;/em&gt; fast and nowadays it can do almost anything on any operating system and/or browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Quick" Reference Guide
&lt;/h2&gt;

&lt;p&gt;Yeah, this is not going to be a short a list of functions or syntax. Below are my notes for mod 3 of my coding bootcamp that I refer back to often because I'm not going to memorize all of this anytime soon -- I will at some point because that's how I do.&lt;/p&gt;




&lt;h3&gt;
  
  
  DOM &amp;amp; Just Enough JavaScript
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Document-Object Model
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;ask DOM to find or select HTML elements or elements in the rendered page&lt;/li&gt;
&lt;li&gt;remove and/or insert element(s)&lt;/li&gt;
&lt;li&gt;adjust a property of selected element(s)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  JavaScript / DOM relationship
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;DOM only knows js, js and DOM are linked at hip from start&lt;/li&gt;
&lt;li&gt;learning about DOM will require js&lt;/li&gt;
&lt;li&gt;"sight words" to do this&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  "Sight Words"
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;basic vocab that forms foundation for more learning latter&lt;/li&gt;
&lt;li&gt;js Sight Words = brief code snippets that are foundational&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Just Enough JavaScript
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;learning sight words first is an interactive way of learning js&lt;/li&gt;
&lt;li&gt;MDN's JavaScript Reference &lt;/li&gt;
&lt;li&gt;code, code, code, code, code&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Coding in Chrome DevTools
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;writing &lt;code&gt;1 + 1&lt;/code&gt; is an expression

&lt;ul&gt;
&lt;li&gt;a valid unit of code that returns a value&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;math expressions are "raw" in console&lt;/li&gt;
&lt;li&gt;literal text is wrapped in quotes&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  "Things" in JavaScript
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;number (integer or float) are things&lt;/li&gt;
&lt;li&gt;string is a thing &lt;/li&gt;
&lt;li&gt;reserved words
var, let, const

&lt;ul&gt;
&lt;li&gt;var came first, now we have let and const&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Template Literals

&lt;ul&gt;
&lt;li&gt;with template literals use back ticks, not single quotes&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  JavaScript is Object-Oriented
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;code i can talk to that know state and behavior&lt;/li&gt;
&lt;li&gt;all Things in js

&lt;ul&gt;
&lt;li&gt;objects&lt;/li&gt;
&lt;li&gt;arrays&lt;/li&gt;
&lt;li&gt;strings&lt;/li&gt;
&lt;li&gt;numbers&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;dot notation()&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  JavaScript has loops
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;for each character in slytherin collection, I would like the harry_potter object to invoke expelliarmus method on each wizard passed in as an argument
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;slytherins&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;harry_potter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;expelliarmus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;slytherins&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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;h3&gt;
  
  
  Variables
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Multi-line Variable Assignment&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Equivalent To:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
    &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Can be Converted To:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use &lt;code&gt;typeof&lt;/code&gt; operator to check data type of value currently stored in a variable.&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; instead of &lt;code&gt;var&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;scope issues with 'var'&lt;/li&gt;
&lt;li&gt;let will throw an error if declare same var more than once&lt;/li&gt;
&lt;li&gt;const cannot be reassigned

&lt;ul&gt;
&lt;li&gt;assign a primitive value (any data type except object)&lt;/li&gt;
&lt;li&gt;a const will always point to same object&lt;/li&gt;
&lt;li&gt;const is self commenting&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;em&gt;NEVER USE VAR&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;USE LET WHEN I KNOW A VALUE NEEDS TO CHANGE (COUNTERS, LOOPS, ETC...)&lt;/li&gt;
&lt;li&gt;USER CONST FOR EVERY OTHER VARIABLE&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  The DOM Tree
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;document.querySelector(selector)&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;selector is like a query string lets me find things within HTML page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The DOM Tree:&lt;br&gt;
(e) = element&lt;br&gt;
(t) = text&lt;br&gt;
(a) = attribute&lt;br&gt;
Document&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;|-- &amp;lt;html&amp;gt; (e)
|---- &amp;lt;head&amp;gt; (e)
    |-- &amp;lt;title&amp;gt; (e)
      |-- &amp;lt;My title&amp;gt; (t)
  |-- &amp;lt;body&amp;gt;
      |-- &amp;lt;h1&amp;gt; (e)
          |-- &amp;lt;A heading&amp;gt; (t)
      |-- &amp;lt;a&amp;gt; (e) - &amp;lt;href&amp;gt; (a)
          |-- &amp;lt;Link text&amp;gt; (t)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finding a Node&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByTagName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DOM Tree:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;main&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find the &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; element: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;const main = document.getElementsByTagName('main')[0]&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Get the children of &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;const div = main.children[1]&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Get and update the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;const p = div.getElementsByTagName('p')[0]&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Change &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;p.textContent = "Goodbye!"&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  JS Fundamentals: Arrays
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;document.getElementsByClassName() =&amp;gt;&lt;/code&gt; [...many elements...]&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTMLCollection, not actually an Array&lt;/li&gt;
&lt;li&gt;HTMLCollection know its length, can be iterated over with for...in... loop&lt;/li&gt;
&lt;li&gt;HTMLCollection not technically an Array&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;document.getElementsByTagName() =&amp;gt;&lt;/code&gt;[...multiple elements...]&lt;/p&gt;

&lt;p&gt;&lt;code&gt;document.getElementById() =&amp;gt;&lt;/code&gt; single element&lt;/p&gt;




&lt;h3&gt;
  
  
  Looping and Iteration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;initialization&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;iteration&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;span class="nx"&gt;loop&lt;/span&gt; &lt;span class="nx"&gt;body&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;ul&gt;
&lt;li&gt;use a for loop when I know exactly how many times I want/need the loop to run&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  querySelector Methods
&lt;/h3&gt;

&lt;p&gt;Learning Goals&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use document.querySelector() &amp;amp; document.querySelectorAll() to find nested nodes&lt;/li&gt;
&lt;li&gt;Change value of targeted DOM nodes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Introduction&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;essential skill, find elements in DOM&lt;/li&gt;
&lt;li&gt;document.getElementById() &amp;amp; document.getElementsByClassName() are good, using tree structure &amp;amp; tags is better&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use document.querySelector() &amp;amp; document.querySelectorAll() to find Nested Nodes&lt;/p&gt;

&lt;h3&gt;
  
  
  document.querySelector()
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;1 arg, CSS-compatible selectors&lt;/li&gt;
&lt;li&gt;returns first instance of arg&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"ranked-list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
              &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
             
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"unranked-list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;6&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;4&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt; **
        &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;const li2 = document.querySelector('ul.ranked-list li ul li')&lt;/p&gt;

&lt;p&gt;const div4 = document.querySelector('ul.unranked-list li div')&lt;/p&gt;




&lt;h3&gt;
  
  
  document.querySelectorAll()
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;1 arg&lt;/li&gt;
&lt;li&gt;returns a NodeList collection

&lt;ul&gt;
&lt;li&gt;an Array, but not technically an Array&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;main&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"ranked-list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
             
    &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"ranked-list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;10&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;11&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;document.getElementById('app').querySelectorAll('ul.ranked-list li')&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;// =&amp;gt; list of Nodes: &amp;lt;li&amp;gt;1&amp;lt;/li&amp;gt;, &amp;lt;li&amp;gt;2&amp;lt;/li&amp;gt;, &amp;lt;li&amp;gt;10&amp;lt;/li&amp;gt;, &amp;lt;li&amp;gt;11&amp;lt;/li&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Removing, Altering &amp;amp; Inserting HTML
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;document.querySelect('element-name').remove()&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;this is to remove an element&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;document.classOrIdThing.remove('thing-name-here')&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;removes a class or id from an element, leaves the element in place&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Explicit and Safe &lt;code&gt;.remove()&lt;/code&gt; pattern&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;element#id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parentNode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explicit and Safe adding
&lt;/h4&gt;

&lt;p&gt;We’ve been inundated by cat owners who are angry that we have missed their favorite species of pet. What JavaScript snippet will add an li with a span inside with the text "Nancy Drew (the cat)" inside to our ul?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nx"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByTagName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;parentNode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
 &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;span&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
 &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
 &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nancy Drew (the cat)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
 &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
 &lt;span class="nx"&gt;base&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  JavaScript Everything
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Different Types of User Events
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;mouse click

&lt;ul&gt;
&lt;li&gt;click, double-click, right-click, etc ...&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;key press 

&lt;ul&gt;
&lt;li&gt;keypress, keydown, keyup&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;form submission

&lt;ul&gt;
&lt;li&gt;submit
ton of browser events&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Functions in js
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;most important thing in js&lt;/li&gt;
&lt;li&gt;a series of multiple tasks can be pulled into a function if the series can be generalized 

&lt;ul&gt;
&lt;li&gt;makes the tasks repeatable&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Scope
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;global scope

&lt;ul&gt;
&lt;li&gt;accessible everywhere in js code&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;block scope

&lt;ul&gt;
&lt;li&gt;let &amp;amp; const&lt;/li&gt;
&lt;li&gt;only within their function&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;variables declared w/out const, let, or (NO!!!!!) var are always globally-scoped

&lt;ul&gt;
&lt;li&gt;even within a block&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Chain Scope
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Chain Scope is using global vars in a local context &lt;/li&gt;
&lt;li&gt;matters where it is declared, not invoked&lt;/li&gt;
&lt;li&gt;local vars can reference outer scoped vars all the way up the levels&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Lexical Scoping
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;scope based on where vars &amp;amp; blocks defined by developer at writing, solidified when code is processed&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Hoisting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;by time js engine reaches execution phase all functions are in memory so order is not important in the code itself&lt;/li&gt;
&lt;li&gt;best way to avoid confusion, declare all functions at the top of my code

&lt;ul&gt;
&lt;li&gt;refactor as needed/on-going or otherwise&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;use let &amp;amp; const as js engine !allow referenced before initialized&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Object Iteration
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;for ... of&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use with arrays, actual ordered data
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-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;myArray&lt;/span&gt; &lt;span class="o"&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;a&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;b&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;c&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;d&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;e&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;f&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;g&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="err"&gt; &lt;/span&gt;
 &lt;span class="k"&gt;for &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;el&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&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;&lt;code&gt;for ... in&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use with objects where order is not required just the key/value pair
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-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;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;street1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;11 Broadway&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;street2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2ns Floor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New York&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;zipCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10004&lt;/span&gt;
 &lt;span class="p"&gt;};&lt;/span&gt;
 &lt;span class="k"&gt;for &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;key&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="p"&gt;};&lt;/span&gt;
 &lt;span class="c1"&gt;// console.log(address[key]) will return the value of the key&lt;/span&gt;
 &lt;span class="c1"&gt;// console.log(key) will return the key&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Ruby Rails RESTful &amp; CRUD Quick Reference</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Sat, 29 Feb 2020 16:17:01 +0000</pubDate>
      <link>https://forem.com/jbshipman/ruby-rails-restful-crud-quick-reference-4c4n</link>
      <guid>https://forem.com/jbshipman/ruby-rails-restful-crud-quick-reference-4c4n</guid>
      <description>&lt;h1&gt;
  
  
  Rails RESTful
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Generate function
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Rails g model
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;rails g model tablename column1 column2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Tablename, this needs to be what your model is going to be called. &lt;/p&gt;

&lt;p&gt;Rails 6 has plurallize built in so it'll make the model singular but keep the table plural as is best practice. To set them as other data types just state them as other than a string.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;column1:integer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;All the useful data types, there are more but these will get the job done most of the time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;integer&lt;/li&gt;
&lt;li&gt;float&lt;/li&gt;
&lt;li&gt;timestamp&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Rails g controller
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;rails g controller ControllerslName controller actions&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;ControllersName needs to reference the model with the following convention &lt;/p&gt;

&lt;p&gt;&lt;code&gt;ModelsController&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The controller actions are, by default, empty unless you specifiy them. The convention is the following order &lt;/p&gt;

&lt;p&gt;&lt;code&gt;index show new edit create update destroy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will setup those seven routes in &lt;code&gt;routes.rb&lt;/code&gt; as well create app/views/model and .html.erb files for each route&lt;/p&gt;

&lt;h3&gt;
  
  
  routes.rb
&lt;/h3&gt;

&lt;p&gt;after runing &lt;code&gt;rails g controller&lt;/code&gt; command like above the routes.rb file will be created with the following boilerplate code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="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;get&lt;/span&gt; &lt;span class="s1"&gt;'/models/index'&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/models/show'&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/models/new'&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/models/edit'&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/models/create'&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/models/update'&lt;/span&gt;
  &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/models/destroy'&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 is fine as is or it can be refactored down to a single line &lt;code&gt;resources :models&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;If you only generate a controller action as needed then the routes and view file will need to be created manually as you go. This may be a better method of going about building out the basic functionality of your web app to be honest as there will be no routes that are unknown to you as the dev.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;side note:&lt;/em&gt; I didn't follow that pattern of build only what you need as you go, and in the last code challenge I found myself lost quickly.&lt;br&gt;
While troubleshooting I knew there was more in the app than I had full understanding of. &lt;br&gt;
In the future I will build controller actions out 1 at a time as I need the functionality and route.&lt;/p&gt;

&lt;p&gt;To take advantage of &lt;code&gt;resources :models&lt;/code&gt; with only specific routes (the buils it as you go method) there is a way to have rails only create those routes you need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:models&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;:index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:show&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can add to the list within the brackets as you build out your web app.&lt;/p&gt;

&lt;h3&gt;
  
  
  controller action methods
&lt;/h3&gt;

&lt;p&gt;For every route you need a controller action method. These live in the ./app/controllers/models_controller.rb file. Each model has a controller and they each inherit from application_controller.rb. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is a great file to place repeated logic in different models, just have the method in the application_controller.rb and all models will have access to the method&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  index
&lt;/h4&gt;



&lt;div class="highlight js-code-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;index&lt;/span&gt;
  &lt;span class="vi"&gt;@models&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For index the only thing really needed is &lt;code&gt;@models = Model.all&lt;/code&gt; as this will provide the logic needed to be able to access all data in the dB table for the model. This is useful as an index web page that lists out everything - table of contents, or all users, or all whatevers.&lt;/p&gt;

&lt;h4&gt;
  
  
  show
&lt;/h4&gt;



&lt;div class="highlight js-code-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;show&lt;/span&gt;
  &lt;span class="vi"&gt;@model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Model&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;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&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;This ensures that a show page for any indivdual record in the dB table for the model can be accessed. This line of code is actually used often in other controller action methods and can be moved to a &lt;code&gt;before_action&lt;/code&gt; macro (more on that later though).&lt;/p&gt;

&lt;h4&gt;
  
  
  new
&lt;/h4&gt;



&lt;div class="highlight js-code-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;new&lt;/span&gt;
  &lt;span class="vi"&gt;@model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another brief bit of logic that makes sure the page will send a &lt;code&gt;.new&lt;/code&gt; command to the dB to kick off the creation of a new record. Additional logic could go here that would pull in more logic for a New page in the browser.&lt;/p&gt;

&lt;h4&gt;
  
  
  update
&lt;/h4&gt;



&lt;div class="highlight js-code-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;update&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 is the best place to any logic for creating, editing, or updating a record. Placing validation logic here will ensure that when you create the update view and use &lt;code&gt;form_for&lt;/code&gt; that a submit button will change it's wording to match the actual action. This is super cool rails magic as it will first check if the record id exists, if it does then it'll pull in the record data to your &lt;code&gt;form_for&lt;/code&gt; form and the submit button will say 'update'. If there is no record then the &lt;code&gt;form_for&lt;/code&gt; form will be empty and the submit button will say 'create'. Also if all routes to any of these actions (craete, or update) are set to the same route than rails again will make sure everything works as expected. Basically just user the update route and rails will take care of it.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>controllers</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Reflections on mod 1</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Mon, 17 Feb 2020 21:47:19 +0000</pubDate>
      <link>https://forem.com/jbshipman/reflections-on-mod-1-5d9o</link>
      <guid>https://forem.com/jbshipman/reflections-on-mod-1-5d9o</guid>
      <description>&lt;p&gt;&lt;em&gt;Mod 1, week 3&lt;/em&gt; is nearing completion. We present our projects tomorrow (20200214) and I feel good about the project I worked on. &lt;/p&gt;

&lt;p&gt;The important thing though is how do I feel now that I have spent the last 3 weeks being a developer (esentially).... &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;I feel great!!&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;I feel that this choice to take 15 weeks to focus deeply on my career transition is not only an extended form of healthy self-care but a really good investment in my own future.&lt;/p&gt;

</description>
      <category>codingbootcamp</category>
      <category>devblog</category>
    </item>
    <item>
      <title>ActiveRecord &amp; Rake cheatsheet</title>
      <dc:creator>James Shipman</dc:creator>
      <pubDate>Thu, 13 Feb 2020 21:20:40 +0000</pubDate>
      <link>https://forem.com/jbshipman/activerecord-rake-cheatsheet-21l6</link>
      <guid>https://forem.com/jbshipman/activerecord-rake-cheatsheet-21l6</guid>
      <description>&lt;p&gt;There is a lot to learn when first learning ActiveRecord and Rake. So much so that I created a cheatsheet for myself. This is a quick reference guide for the basic folder structure ActiveRecord (just AR for now) and Rake look for as well as what each file needs to get everything up and running.&lt;/p&gt;

&lt;h2&gt;
  
  
  Folder Structure
&lt;/h2&gt;

&lt;p&gt;root.&lt;br&gt;
 ./ &amp;lt; Gemfile &amp;gt;&lt;br&gt;
 ./ &amp;lt; Rakefile &amp;gt;&lt;br&gt;
 ./app&lt;br&gt;
 ./app/models/ &amp;lt; model_file.rb &amp;gt;&lt;br&gt;
 ./bin &amp;lt; run.rb &amp;gt;&lt;br&gt;
 ./config &amp;lt; environment.rb &amp;gt;&lt;br&gt;
 ./db &amp;lt; seeds.rb &amp;gt;, &amp;lt; schema.rb &amp;gt;&lt;br&gt;
 ./db/migrate/ &amp;lt; 001_migration_file.rb &amp;gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Files
&lt;/h2&gt;

&lt;p&gt;For each file there are some basics that each file needs and ActiveRecord. Here is each file as noted above.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;Gemfile&lt;/code&gt; - this file lists all gems being used in your app. Note in the line for activerecord it calls to a version number, this is optional.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"https://rubygems.org"&lt;/span&gt;

&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s2"&gt;"activerecord"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'~&amp;gt; 5.2'&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s2"&gt;"sinatra-activerecord"&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s2"&gt;"sqlite3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'~&amp;gt; 1.3.6'&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s2"&gt;"pry"&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s2"&gt;"require_all"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;code&gt;Rakefile&lt;/code&gt; - this file establishes connections within the folder structure and creates a live environment through &lt;code&gt;rake console&lt;/code&gt; that allows for testing.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require_relative&lt;/span&gt; &lt;span class="s1"&gt;'config/environment'&lt;/span&gt;
&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'sinatra/activerecord/rake'&lt;/span&gt;

&lt;span class="n"&gt;desc&lt;/span&gt; &lt;span class="s1"&gt;'starts a console'&lt;/span&gt;
&lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="ss"&gt;:console&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Logger&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="no"&gt;STDOUT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="no"&gt;Pry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;model_file - these are highly specific but the minimum. This file acts as the model that matches a table in the app's database. It is a &lt;em&gt;good idea&lt;/em&gt; to keep the name here matched to migration file and table that this model file provides custom functionality to.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ModelName&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;code&gt;run.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require_relative&lt;/span&gt; &lt;span class="s1"&gt;'../config/environment'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;code&gt;environment.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'bundler'&lt;/span&gt;
&lt;span class="no"&gt;Bundler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;

&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'active_record'&lt;/span&gt;

&lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;establish_connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="ss"&gt;adapter: &lt;/span&gt;&lt;span class="s1"&gt;'sqlite3'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
  &lt;span class="ss"&gt;database: &lt;/span&gt;&lt;span class="s1"&gt;'db/development.db'&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;require_all&lt;/span&gt; &lt;span class="s1"&gt;'app/models'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;code&gt;seeds.rb&lt;/code&gt; - this file will contain test data that can be loaded into the app's database. Prior to creating the seed data it is a great idea to have a line per model that deletes everything out of the data table for that model. This way the seed data can be reloaded as needed and old data will be removed.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delete_all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;schema.rb&lt;/code&gt; - This file is created by ActiveRecord, do not edit it manually but it is good to reference back to it as it will contain the lastest version of the schema for all tables within your database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;001_migration_file.rb&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreateProteinTable&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Migration&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;5.2&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;change&lt;/span&gt;
    &lt;span class="n"&gt;create_table&lt;/span&gt; &lt;span class="ss"&gt;:proteins&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
      &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt; &lt;span class="ss"&gt;:name&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;/li&gt;
&lt;/ol&gt;

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