<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zachary Sirna</title>
    <description>The latest articles on DEV Community by Zachary Sirna (@zander618).</description>
    <link>https://dev.to/zander618</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F820016%2Ff1653e66-3ac2-4cb6-ac9b-8b06ffbafa3c.png</url>
      <title>DEV Community: Zachary Sirna</title>
      <link>https://dev.to/zander618</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zander618"/>
    <language>en</language>
    <item>
      <title>Aliased Associations Ruby on Rails</title>
      <dc:creator>Zachary Sirna</dc:creator>
      <pubDate>Thu, 16 Mar 2023 20:43:07 +0000</pubDate>
      <link>https://dev.to/zander618/aliased-associations-ruby-on-railsreact-client-1dj5</link>
      <guid>https://dev.to/zander618/aliased-associations-ruby-on-railsreact-client-1dj5</guid>
      <description>&lt;p&gt;In Ruby on Rails, foreign keys are used to establish associations between different models. They allow you to link records in one table to records in another table. These foreign keys create relationships between tables. Although sometimes you may need to have two different keys from the same model in a new model. In this blog post, I'm going to briefly demonstrate how to use foreign keys in Ruby on Rails to do it.&lt;/p&gt;

&lt;p&gt;Let's say you have a "User" model, and you want to create a new model called "Meeting" to store information about meetings between users. Each user will have need a unique foreign key. Lets call the foreign keys "sender_id" and "receiver_id". Both of which will use the "id" column in the "User" model.&lt;/p&gt;

&lt;p&gt;Now the first place to start when must creating this association is the new model.&lt;/p&gt;

&lt;p&gt;Create the "Meeting" model: &lt;/p&gt;

&lt;p&gt;First, we need to create a new model called "Meeting" using the Rails generator:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JPlqWGHE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/247g02gr205pq866fu30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JPlqWGHE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/247g02gr205pq866fu30.png" alt="Image description" width="160" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will create a new migration file for the "Meeting" model. Now we need to go into the migration file to update that before migrating.&lt;/p&gt;

&lt;p&gt;Update the migration file:&lt;/p&gt;

&lt;p&gt;Now we need to update the migration file to have foreign keys. One for the user receiving the meeting and one for the user sending the meeting. The foreign keys of "receiver_id" and "sender_id" will allow the user id to be passed as an alias to the meeting table twice one user as a receiver and one user as a sender.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pMFUikDq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b77tmnz2q3wl2q2ejiox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pMFUikDq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b77tmnz2q3wl2q2ejiox.png" alt="Image description" width="530" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then run "rail db:migrate"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UYUr7A8o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51z0rjuzly8wrrai1f87.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UYUr7A8o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51z0rjuzly8wrrai1f87.png" alt="Image description" width="153" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Update the models:&lt;/p&gt;

&lt;p&gt;Finally, we need to update the "User" and "Meeting" models to establish the associations between them:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZcBeSzCd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4oby6972110h0ljrml6u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZcBeSzCd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4oby6972110h0ljrml6u.png" alt="Image description" width="775" height="107"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DoKBpYGY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6oweu74kc32jdw1so4hm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DoKBpYGY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6oweu74kc32jdw1so4hm.png" alt="Image description" width="704" height="130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the "User" model, we have two "has_many" associations with the "Meeting" model. The "has_many :sent_meetings" and "has_many :received_meetings" They both point to the class name of "Meeting" and have unique foreign keys. &lt;/p&gt;

&lt;p&gt;In the "Meeting" model, it has two "belongs_to" associations with the "User" model. We used the "class_name" option to specify the name of the associated model, and specified it to use the same foreign key that associates with it from the "User" model.&lt;/p&gt;

&lt;p&gt;Now you can create and retrieve meetings between users. With each Meeting having two foreign keys from the "User" model you can now call "user.received_meetings" or "user.sent_meetings" to retrieve the associated data. As always still a student so I am still learning but hopefully this has been helpful.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Basic Secure User Sign-up using Ruby on Rails</title>
      <dc:creator>Zachary Sirna</dc:creator>
      <pubDate>Mon, 31 Oct 2022 19:00:58 +0000</pubDate>
      <link>https://dev.to/zander618/basic-secure-user-sign-up-using-ruby-on-rails-2je5</link>
      <guid>https://dev.to/zander618/basic-secure-user-sign-up-using-ruby-on-rails-2je5</guid>
      <description>&lt;p&gt;I am going to go over setting up a user sign-up, sign-out, and logout using sessions for authorization with Ruby on Rails. Side note I will not be going into putting this into application on the frontend.&lt;/p&gt;

&lt;p&gt;Before I jump I will describe session data. In Ruby on rails the application can hold small amounts of data for each user. That data will remain between requests. We will need to store that data using cookies. It must be set up in the controllers. As we go through we will get into creating the session in the controller and enabling cookies.&lt;/p&gt;

&lt;p&gt;We are going to start from scratch. In your terminal create a new folder and the cd into that folder. Then while in that folder type "rails new the-app-name --api --minimal --database=postgresql". This will build a new rails project using Postgresql. I am choosing Postgres incase this project will be deployed later using Heroku.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--la7lbchq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d9ee7333uh2n9qve0ggx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--la7lbchq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d9ee7333uh2n9qve0ggx.png" alt="Image description" width="812" height="43"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now open the project on a code editor. I will be using VsCode. The gem for 'bcrypt' must be add to the Gemfile. bcrypt() is a sophisticated and secure hash algorithm designed by The OpenBSD project for hashing passwords. The bcrypt Ruby gem provides a simple wrapper for safely handling passwords.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K3gUBCdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6u46b5pmvj8347d9zkyr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K3gUBCdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6u46b5pmvj8347d9zkyr.png" alt="Image description" width="880" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we want to run bundle install. This will install all the necessary the Gemfile dependencies needed from the terminal.&lt;br&gt;
Then we need to use some generators to create a model, a migration file and controller for user and a sessions controller . Run rails g resource User to create a model a controller for the User being signed up, logged in, or logged out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--arADCZLi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qpopzpkqgs53lsii29ob.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--arADCZLi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qpopzpkqgs53lsii29ob.png" alt="Image description" width="381" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we can just use a controller generator for the sessions controller. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YOWdT1Xq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gk91jj104s1w6zw578gg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YOWdT1Xq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gk91jj104s1w6zw578gg.png" alt="Image description" width="262" height="37"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to code the necessary columns to our user migration file. We will add a username and a password_digest. password_digest stores the salted password and the return value of BCrypt. It then concatenates them to produce a character string to separate them. This creates a very secure way of storing and encrypting passwords.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--viM7UQnM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7svyefe4jva0feku9anf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--viM7UQnM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7svyefe4jva0feku9anf.png" alt="Image description" width="880" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now start the Postgres server, run rails db:create, and finally run rails db:migrate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ALG4TnYG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2s7dqe07ik6xs6ckwema.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ALG4TnYG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2s7dqe07ik6xs6ckwema.png" alt="Image description" width="752" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Time to begin our coding by starting in the routes file. We create two posts, a get, and a delete. The “/me” route will be used to allow the front end to know who the user is after when the page loads. The “signup” route will allow a user to create their username and password. The “/login” will verify and then login the user. Then finally the logout will remove the stored session.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1LM__3Gn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iobkdpnbsjgqnx4q5gs8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1LM__3Gn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iobkdpnbsjgqnx4q5gs8.png" alt="Image description" width="533" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following add has_secure_password and validations into the User model. The has_secure_password adds methods to set and authenticate against a BCrypt password. Then the validations will ensure there will only be no duplicate usernames and that a username must be added in order to successfully process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f9fIza5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka1c7m3wdjwchinbfkra.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f9fIza5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka1c7m3wdjwchinbfkra.png" alt="Image description" width="554" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Afterwards add a create and show inside the User controller. The User create will allow a user to sign up. It will then store the user id in the session. That will be passed to our application controller, that we will set up shortly, which will authorize and then send back to our show method the instance method of the current user to show the frontend to the current user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VlyhYhrJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0wv4gvw9j6zv23yzt5y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VlyhYhrJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0wv4gvw9j6zv23yzt5y.png" alt="Image description" width="857" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to create a show and destroy in the Sessions controller. The create method in this controller will allow a user to sign in. It will authenticate the username and the password and then it will send the session id over to the application controller which will authorize and then send back to our show method the instance method of the current user to show the frontend to the current user. The the destroy method will remove the session and the user will be successfully logged out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ih51n7rR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/igz81ootajzsti86f4my.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ih51n7rR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/igz81ootajzsti86f4my.png" alt="Image description" width="880" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly we will update the Application controller in order to find the current user based off the session user id to create an instance of the current user. Before it performs this action it will authorize which is why we have added before_action :authorize. We have also included an ActionController for Cookies so the session data can be temporarily saved. Plus we are adding a rescue from incase the information provided is incorrect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qPscAaTF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yej8qppkyo31u6jvae0n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qPscAaTF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yej8qppkyo31u6jvae0n.png" alt="Image description" width="880" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to add Cookies into the config file. A cookie is a piece of data from a website that is stored within a web browser that the website can retrieve at a later time. Cookies are used to tell the server that users have returned to a particular website. This allows for the frontend to temporarily store our sessions data so that the current user will persist while using the website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dhMiVjDQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h7xff32ex3x7kuazcfaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dhMiVjDQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h7xff32ex3x7kuazcfaf.png" alt="Image description" width="832" height="641"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have a backend ready to talk to the frontend to use a secure user sign-in, sign-up, login and logout. I am currently still a student so I am also still learning but hopefully this has been helpful. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting started, Sinatra Backend with Active Record(Ruby)</title>
      <dc:creator>Zachary Sirna</dc:creator>
      <pubDate>Thu, 02 Jun 2022 19:16:52 +0000</pubDate>
      <link>https://dev.to/zander618/getting-started-sinatra-backend-with-active-recordruby-59n0</link>
      <guid>https://dev.to/zander618/getting-started-sinatra-backend-with-active-recordruby-59n0</guid>
      <description>&lt;p&gt;I just want to give a brief overview on how one can get started building a backend that uses Sinatra with Active Record coding in Ruby. With this blog there are some assumptions that one will know the frontend CRUD to talk to the backend. Let's start with a new VS code window. &lt;/p&gt;

&lt;p&gt;We are going to create a bunch of folders and files. For now let's go off this screen shot. Everything on here is empty so we will go into the purposes of each and fill them out as we go.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j2foHvGJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eg5utz8788nlb3uag6a3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j2foHvGJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eg5utz8788nlb3uag6a3.png" alt="Image description" width="245" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let s start with our Rakefile.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U6rnNjQ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb6o6zz73wkm9egqffcx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U6rnNjQ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb6o6zz73wkm9egqffcx.png" alt="Image description" width="737" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is happening here is the first description will start the server for us once we enter into the console and type rake server. The next two lines are designating a port in which to run the local server on. Then the next line rerun allows auto-reloading of server when files are updated. Finally the last line allows us to call rake console in the terminal to enter into Pry.&lt;/p&gt;

&lt;p&gt;Now our Gemfile. I'll leave in the comments as there own descriptions of each gem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nQDw1B8C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5nl481i613stirsqcuxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nQDw1B8C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5nl481i613stirsqcuxc.png" alt="Image description" width="880" height="634"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our config.ru will look like this. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sHZpQgwL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgc8j9wxn7v3oi2gi8ci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sHZpQgwL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgc8j9wxn7v3oi2gi8ci.png" alt="Image description" width="827" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rack::Cors allows for Cross-Origin Resource Sharing request. Rack:JSONBodyParser will parse the json from the request body into params hashes.&lt;/p&gt;

&lt;p&gt;Next we are going to go all the way up to the config/ environment.rb. We will not use the db migrate until we start building our tables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HASAbuhD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6nn0adi4ocm7pl1iu2zl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HASAbuhD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6nn0adi4ocm7pl1iu2zl.png" alt="Image description" width="471" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first line is an environment variable that is used by some of the Rake tasks to determine if our application is running locally in development, in a test environment, or in production. The next two lines require our Gems.The last line requires all files in 'app' directory.&lt;/p&gt;

&lt;p&gt;Finally we just need to create the inheratence relationship in our Application Controller.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TlTp8OgE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pxy95aonelj3oe9uq3f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TlTp8OgE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pxy95aonelj3oe9uq3f.png" alt="Image description" width="533" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alright now lets create some tables to work with. Open your terminal and cd into Server. Run "bundle install". That will install all of our gems. Now we can create our tables. We will create a table called "humans". Type "rake db:create_migration NAME=humans". Once you hit enter you will see that the terminal will display that there is a new file in the migrate folder. You will also see it in the explorer with the timestamp that it was created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--om2bcVSh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2atpz4v7ihrakzxnhn6y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--om2bcVSh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2atpz4v7ihrakzxnhn6y.png" alt="Image description" width="772" height="34"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r9D330xR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avaxdcq9fydb7ju9b7fh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r9D330xR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avaxdcq9fydb7ju9b7fh.png" alt="Image description" width="247" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember that we need to be very specific with our naming conventions. Models and Classes are singular. Tables and schema are plural.&lt;/p&gt;

&lt;p&gt;Let's create another table called "dogs". Then we will create a relationship between the two and build the tables. Type "rake db:create_migration NAME=dogs" into the teminal. Alright now we have two tables to work with. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2vL7DHrG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/076y5cuo0ex6wv5p4tqm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2vL7DHrG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/076y5cuo0ex6wv5p4tqm.png" alt="Image description" width="239" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our humans migrate file we will create a table using the "create_table method. It will look like the following to give us three columns. The id will be the first column and that will be auto generated. The second will be their first name and the last will be their last_name.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iy4epFcd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/96pndolvo738t2jgersg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iy4epFcd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/96pndolvo738t2jgersg.png" alt="Image description" width="432" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets work on our dogs. It will look very similar but we will add a foriegn key to establish a relationsip between a dog and their human.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oumBqTQX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqj8fkishfh4a8294mny.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oumBqTQX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqj8fkishfh4a8294mny.png" alt="Image description" width="417" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can run "rake db:migrate" to create our SQLite tables. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--buJYH21V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0i4ulbq4tvtpr7hiy7y7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--buJYH21V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0i4ulbq4tvtpr7hiy7y7.png" alt="Image description" width="631" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can now see the schema that was created by active record as well.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bLf2covQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljqpmxsc7cylfzpo71w6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bLf2covQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljqpmxsc7cylfzpo71w6.png" alt="Image description" width="880" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In app/models we build the classes for dogs and humans. Remember their classes will be singular. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ClxAfI0I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/myf7g4n2zxoqxl43zrgu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ClxAfI0I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/myf7g4n2zxoqxl43zrgu.png" alt="Image description" width="234" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our classes will look like the following inheriting from ActiveRecord::Base. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Emuzdpvm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wb83321njz68611cla8u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Emuzdpvm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wb83321njz68611cla8u.png" alt="Image description" width="310" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xkkhmZ4h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38lubgheg93hhy9dr6d0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xkkhmZ4h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38lubgheg93hhy9dr6d0.png" alt="Image description" width="327" height="94"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have the base for our Sinatra backend. Next blog we will go over how to create instances of the classes to populate data. Also how to create a seed file to add data. Then how to use the Application Controller to allow for CRUD. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Adding A PopUp with JSX and Components</title>
      <dc:creator>Zachary Sirna</dc:creator>
      <pubDate>Tue, 19 Apr 2022 17:59:35 +0000</pubDate>
      <link>https://dev.to/zander618/adding-a-popup-with-jsx-and-components-2com</link>
      <guid>https://dev.to/zander618/adding-a-popup-with-jsx-and-components-2com</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HL2q8w3W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cnuel86zyxno773nr0z.GIF" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HL2q8w3W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cnuel86zyxno773nr0z.GIF" alt="Image description" width="880" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For my second project for school I built a web based application for sifting through a database of movies. This application allows users to select movies out of a database and then add them to their personal watch list. I didn't want the movie list component of the application to get too crowded with information so I wanted to implement a pop up window. Unfortunately the popup window wasn't as simple to implement as I had hoped. In this blog I will provide my insights on what I have learned and hopefully it will help others. Note I'm still learning and this is more so guidance then a full lesson from an expert.&lt;/p&gt;

&lt;p&gt;Let's get started. Here is a link to my repo. Clone and follow the ReadMe to run this in your code editor. &lt;a href="https://github.com/Zander618/HorrorWatchList"&gt;https://github.com/Zander618/HorrorWatchList&lt;/a&gt;. If you navigate to the MovieList tab you can see what the popup I am refering to looks like if you click more info on any given movie.&lt;/p&gt;

&lt;p&gt;To simplify my instructions I'll start from scratch. If you need additional instrusctions on starting a react app here is a link to React's website to create a react app. &lt;a href="https://create-react-app.dev/"&gt;https://create-react-app.dev/&lt;/a&gt; .After you run npx create-react-app &lt;u&gt;my-app-name&lt;/u&gt; we can navigate into that new folder by cd-ing into it. Let's open it in our code editor using (code .). Then we can open it in the browser with npm start in the terminal or yarn start if you have yarn installed. You should see this as the boilerplate code. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RhssCE4_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pk4i5tu1prm7vzxnbqop.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RhssCE4_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pk4i5tu1prm7vzxnbqop.PNG" alt="Image description" width="880" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alright so the app works. Let's get rid of all this stuff to start with our own code. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zSnjYn9D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu9n4wwgeonv1jsgfypw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zSnjYn9D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu9n4wwgeonv1jsgfypw.PNG" alt="Image description" width="154" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to remove App.css, App.test.js, logo.svg, reportWebVitals.js, and setupTests.js. The index.css can stay for styling. However I will not be going into styling today. Simply right click on the item and go down to delete permanently. In index.js remove the imports related to the components we have deleted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--siBHTYFp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1nwklbdu42lajsmkfttq.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--siBHTYFp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1nwklbdu42lajsmkfttq.PNG" alt="Image description" width="880" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The end result should look like this. Save and move on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--po1c3j8x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2hcvyjilw3rg859mmty3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--po1c3j8x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2hcvyjilw3rg859mmty3.PNG" alt="Image description" width="806" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next in App.js let's delete everything and start from scratch. We are going to simply add an H1 and a button tag between two div tags to the needed component code. I am using the react arrow function component. It should look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WvHu1Cys--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0n87ovlwnpskchcf00a.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WvHu1Cys--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0n87ovlwnpskchcf00a.PNG" alt="Image description" width="503" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have something on our React App :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w65w5_IE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocynvmvxykc4egt41st4.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w65w5_IE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocynvmvxykc4egt41st4.PNG" alt="Image description" width="880" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here we need a new component to be the popup. Click on add new file. Let's call it popup.js. Inside popup.js we are going to create a div tag within a div tag and a button tag inside of the two divs with some class names for some styling.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aPyzPJXB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nc90ba7zlat5nn2qnl7m.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aPyzPJXB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nc90ba7zlat5nn2qnl7m.PNG" alt="Image description" width="542" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's create a popup.css to style this popup. Click on new file and name it popup.css. Without going into styling detail, this css displayed below will center your popup, give it some color to separate from the background and also position the close button in the top right.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O2fxZqza--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mrld67dp285x902xtvk8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O2fxZqza--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mrld67dp285x902xtvk8.PNG" alt="Image description" width="420" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure to import the css into your Popup.js component (import "./popup.css").&lt;/p&gt;

&lt;p&gt;Back to our App.js. Here is the magic. Let's import our Popup.js and then place it under our button. Now let's add state to trigger this popup. Import {useState} above and lets declare state. We will call it [buttonPopup,setButtonPopup]. We are going to set that state to false. Now we need to be able to change that boolean value. We are going to add an on click to our button. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E47XCkkt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hl3fp7a7u9fpkgwtshnr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E47XCkkt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hl3fp7a7u9fpkgwtshnr.png" alt="Image description" width="454" height="32"&gt;&lt;/a&gt;&lt;br&gt;
Finally let's pass that value as a prop to our Popup.js. When done it should look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M2hEBlGu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yw910ncb0340ggbnod5q.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M2hEBlGu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yw910ncb0340ggbnod5q.PNG" alt="Image description" width="654" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now back in our Popup.js. We are going to create a ternary to show the popup using the popup as the true value. If it is truthy it will display the content and if it is falsey it will display nothing. We are going to use an empty string as nothing.  We will then add a title and a description under it using an h3 tag and a p tag. That code should look like the following image below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_NUm56ZS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cgibhgu1k6z6gszx1ifv.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_NUm56ZS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cgibhgu1k6z6gszx1ifv.PNG" alt="Image description" width="724" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Success we have a pop up! When you click on POP UP you'll see our popup. Now we just need to work on closing it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---ewCsrQ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjcdpuuxahp6ewb7i7on.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---ewCsrQ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjcdpuuxahp6ewb7i7on.PNG" alt="Image description" width="880" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to pass our setButtonPopup as a prop to Popup.js. Back in Popup.js we will add that prop and put an onClick to the button inside our divs. We will then set that value to false and that will then change the value back to false. Now we can open and close our popup. SUCCESS!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IrkMAUgc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hafz9g9op1ei5vt8oa5d.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IrkMAUgc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hafz9g9op1ei5vt8oa5d.PNG" alt="Image description" width="793" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>Are you fetching too much?</title>
      <dc:creator>Zachary Sirna</dc:creator>
      <pubDate>Tue, 22 Mar 2022 15:28:59 +0000</pubDate>
      <link>https://dev.to/zander618/phase-1-project-are-you-fetching-too-much-1o1p</link>
      <guid>https://dev.to/zander618/phase-1-project-are-you-fetching-too-much-1o1p</guid>
      <description>&lt;p&gt;You have created an awesome project. Everything works and it looks clean. Let's go and show this to the instructor. The instructor says something like "Wow, I like this. You're doing a great job and I like the progress you're making but...". Oh no they said "but". "But what?" you ask. "You are fetching data an awful lot of times". You now realize that you sure are fetching data a lot. Pretty much every event listener you intergraded is refetching data you could just store. Now the questions are: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do I store this data in a variable?, &lt;/li&gt;
&lt;li&gt;Is it in scope?, &lt;/li&gt;
&lt;li&gt;Am I asking this data to render before it is fetched?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's start with where I went wrong. Here is my website and the API used with the website.  &lt;/p&gt;




&lt;p&gt;&lt;a href="https://zander618.github.io/GhibliRepo/"&gt;https://zander618.github.io/GhibliRepo/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://ghibliapi.herokuapp.com/"&gt;https://ghibliapi.herokuapp.com/&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;You will see that every movie lives in it's own little card and it gets fetched everytime it is called. Fetch one is called on "DOMContentLoaded".&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2Br2Q7Yx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7vyde1h4ajke6yrwd34v.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2Br2Q7Yx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7vyde1h4ajke6yrwd34v.PNG" alt="Image description" width="880" height="732"&gt;&lt;/a&gt;&lt;br&gt;
Now you want to see more information. You click on more information and that same data is fetched again to display a single card. Now you go back to the full collection and LET'S FETCH THAT SAME DATA AGAIN (－‸ლ).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wc0T0ehw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hl2sre3tf7hi0ghgmv1y.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wc0T0ehw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hl2sre3tf7hi0ghgmv1y.PNG" alt="Image description" width="642" height="862"&gt;&lt;/a&gt;&lt;br&gt;
Unfortunately I coded this so every time you go back and forth between all movies and the single more informative image the page is fetching the same data after every event. Let's fix this.&lt;/p&gt;

&lt;p&gt;Step one make sure we are still fetching the data before we remove it from the functions. Let's place that fetch in the "DOMcontentLoaded" event listener and console.log it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0zuejYs9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kq1geutkme4s4x1dpqa5.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0zuejYs9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kq1geutkme4s4x1dpqa5.PNG" alt="Image description" width="880" height="705"&gt;&lt;/a&gt;&lt;br&gt;
Great it's all there. What now? What now, is that we need to store that data somewhere. Let store it in a variable. Make sure it is a  global variable. You don't want it in a function where you will lose access to the variable due to scope issues. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xHOVulwy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5x9xc5go61yj47wlcv48.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xHOVulwy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5x9xc5go61yj47wlcv48.PNG" alt="Image description" width="880" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That should do it right. I told .then to take that data and store it in my newly declared "obj". I then called movieCard for it to get slapped on the DOM. I then changed my "for of"s to iterate through obj instead of data. Nailed it. &lt;/p&gt;

&lt;p&gt;ERROR&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l8R3hn8b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jgjs8p49m58vpyfr4731.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l8R3hn8b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jgjs8p49m58vpyfr4731.PNG" alt="Image description" width="880" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What are you saying console? You can't access 'obj'. It's right there. I see it. You see it. So why is this happening? After some trouble shooting I realized I am asking the content to load before the data is fetched. We are dealing in milliseconds but computers are fast. You may be able to console.log hundreds if not thousands of lines before that fetch returns that promise. Alright we know what we need. Let's set that timeout.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_8NayCUq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ey10qg3mpdy8w1zo98i.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_8NayCUq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ey10qg3mpdy8w1zo98i.PNG" alt="Image description" width="880" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alright. We declared a new variable called load. Added a setTimeout() to that and it calls movieCard. It waits 200 milliseconds after "DOMContentLoaded" calls it. And success!&lt;br&gt;
The page no longer calls fetch, fetch, fetch, fetch ....We just have a small blip as the page loads but we are no longer sending "GET" request to the API endlessly. I hope my short story is helpful to some. As I continue to learn maybe someone can learn from me.   &lt;/p&gt;

</description>
    </item>
    <item>
      <title>FIRST POST(A Start)</title>
      <dc:creator>Zachary Sirna</dc:creator>
      <pubDate>Sun, 27 Feb 2022 23:54:51 +0000</pubDate>
      <link>https://dev.to/zander618/first-posta-start-omb</link>
      <guid>https://dev.to/zander618/first-posta-start-omb</guid>
      <description>&lt;p&gt;I have come to what I can only hope is the end of my audio and video production career path but an end is just a new beginning. Earlier this week i began my first of twenty weeks in FlatIron's twenty week software engineering class. As I travel across this new terrain, I welcome you to follow my journey. In the coming weeks and months I hope to not only develop a large skill set for software engineering but demonstrate it here. Maybe I can help and maybe even inspire others. I have already completed the pre-work for FlatIron and learned a great deal. Especially considering I knew nothing of coding coming into this. Here is my first attempt at a website after one month of pre-work. &lt;a href="https://zander618.github.io/Solve-the-camelCase/"&gt;https://zander618.github.io/Solve-the-camelCase/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>brandnewcoder</category>
    </item>
  </channel>
</rss>
