<?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: Tate Braeckel</title>
    <description>The latest articles on DEV Community by Tate Braeckel (@tbraeck).</description>
    <link>https://dev.to/tbraeck</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%2F905399%2F9f2735c8-d87b-4a4d-81f7-b4c185343490.jpeg</url>
      <title>DEV Community: Tate Braeckel</title>
      <link>https://dev.to/tbraeck</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tbraeck"/>
    <language>en</language>
    <item>
      <title>Using Active Storage for Photo Uploads</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Tue, 07 Nov 2023 15:19:06 +0000</pubDate>
      <link>https://dev.to/tbraeck/using-active-storage-for-photo-uploads-2l9l</link>
      <guid>https://dev.to/tbraeck/using-active-storage-for-photo-uploads-2l9l</guid>
      <description>&lt;p&gt;Wow, made it to the end of my Flatiron School software engineering program! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xBr7vmqz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lspih4wthrqpt9w1z48f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xBr7vmqz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lspih4wthrqpt9w1z48f.gif" alt="surprise" width="200" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My capstone project has been one of the biggest challenges I have ever faced- and I'm old now, so that's saying a lot. The project itself, I feel is a good beginning for an extension project that I will continue to work on after the program has ended: a Craigslist-like app that is specifically for Bartering (goods, services, and another forum for free items or services). I think this could be the beginning of something really fantastic that can actually help, not hinder humans. &lt;/p&gt;

&lt;p&gt;We need more tools like this to help connect us again, to help us help each other, to make the world a more positive place.&lt;/p&gt;

&lt;p&gt;Anyways...I will get going on the Active Storage portion of my app. &lt;/p&gt;

&lt;h2&gt;
  
  
  Active Storage for Image Uploads
&lt;/h2&gt;

&lt;p&gt;I knew that if this type of app was to be successful in today's world, it needed to have photo-video uploading capabilities. People are very visual and very fickle with their time now, so images are a must.&lt;br&gt;
 To accomplish this, I turned to Active Storage, a powerful tool that simplifies the process of uploading files to cloud storage services like Amazon S3, Cloudinary, and Google Cloud Storage- or simply uploading from your local machine. &lt;/p&gt;

&lt;p&gt;To be honest, all the information I went through about Active Storage made it seem really easy to incorporate, I found that to be untrue at the time. I later discovered this was because of a simple error in tertiary code in my code body- discovered by my amazing advisor along the way. So...long story short, Active Storage &lt;em&gt;IS&lt;/em&gt; very user friendly and can be incorporated into your Rails app quickly &lt;em&gt;IF&lt;/em&gt; you don't have foolish mistakes in your code.;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Now for the explanation of Active Storage:
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Selecting Cloud Storage
&lt;/h2&gt;

&lt;p&gt;First, you need to choose a cloud storage provider for your application. In my project, I opted for Amazon S3. Fortunately, a previous student had documented the step-by-step installation process, making it an easy choice. You can follow their guide here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Active Storage
&lt;/h2&gt;

&lt;p&gt;To get started, install Active Storage by running the following commands in the terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails active_storage:install&lt;br&gt;
rails db:migrate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This sets up the necessary tables and foreign key references in your database. Here is a reference image for what my schema looks like for my database after Active Storage installation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CCGtmo8S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edmn6ox7cgu21t527b9b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CCGtmo8S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edmn6ox7cgu21t527b9b.png" alt="code snippet" width="800" height="558"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Active Storage will do all the leg work for attaching images/ videos if you set up the backend properly. You do not need to create an additional column in your table(s) to have hole the image, as the image will be saved in the cloud storage, not in the database.&lt;/p&gt;

&lt;p&gt;This is one of my tables for my different forums as an example of how image is not a column in there: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M3Uz85Or--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ulfjic9x9mu0twt2ruqk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M3Uz85Or--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ulfjic9x9mu0twt2ruqk.png" alt="code snippet" width="687" height="289"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Many-to-Many Relationship&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your use case involves many-to-many relationships between a model and files, make sure to follow Rails naming conventions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modifying the Serializer
&lt;/h2&gt;

&lt;p&gt;You'll need to modify the serializer to create a blob_path for the account image. This path is used to process the image_url into JSON for rendering as an image. I found it simpler to rename the attribute of the image_blob to "main_image" so the method name did not match and confuse things.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KOwwXpma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gyd61gj8o9en9aynvnu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KOwwXpma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gyd61gj8o9en9aynvnu.png" alt="code snippet" width="800" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Association in Model
&lt;/h2&gt;

&lt;p&gt;In your model you will need a specific association syntax for Active Storage associate the image to your model. YOu must have has_one_attached and the name you are giving your attached image. This name does not really matter but needs to be something you can remember and use throughout the app. Like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TXAjB-hW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kbiw8p3mm5049ham3by.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TXAjB-hW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kbiw8p3mm5049ham3by.png" alt="code snippet" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My app only allowed for one attached image, but Active Storage allows for multiple images and videos too. For syntax and extensive information check out the docs &lt;a href="https://edgeguides.rubyonrails.org/active_storage_overview.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;Ensure that your controller is configured correctly. You really only need to add your param name to your strong params: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---KVg3Jrl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sirug1lq1wokpgtrhwo4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---KVg3Jrl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sirug1lq1wokpgtrhwo4.png" alt="code snippet" width="800" height="93"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Now take a short break and get some coffee or a slice of pizza. On to the frontend next!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1Se8nrWW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kh29rkkqwyqi4kbhzyjk.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1Se8nrWW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kh29rkkqwyqi4kbhzyjk.gif" alt="pizza" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Handling
&lt;/h2&gt;

&lt;p&gt;The simplest methods to send data from the JS frontend to the backend is by using the FormData API. First create state for the formData: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AGLmuq1A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/al3nyx9p9it5bqtmlaey.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AGLmuq1A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/al3nyx9p9it5bqtmlaey.png" alt="code snippet" width="677" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, in a handleSubmit function use the formData/ append method. Note: the syntax wit the user_id is required with this method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n0Q3_1yb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9es91ycrzln595qjlf7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n0Q3_1yb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9es91ycrzln595qjlf7.png" alt="code snippet" width="757" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, in you form include an image or images input with similar syntax. The onChange is the most important portion of this and corresponds to an onChange that handles the event and value. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MhpsGw1M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ad5reft59w00w6ki9d4b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MhpsGw1M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ad5reft59w00w6ki9d4b.png" alt="code snippet" width="800" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5CfMpT3w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnf6mcuv8vck1zu08mec.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5CfMpT3w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnf6mcuv8vck1zu08mec.png" alt="code snippet" width="800" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Save everything, then restart your Rails server. This should have done most, if not all the legwork for setting up basic Active Storage for your app. &lt;/p&gt;

&lt;p&gt;Note: Don't try to console.log formData because it will just be an empty object and confuse you. Also, you will know when the image data is going through properly when you see something like this in your rails server: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2Bu8ehC_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8jiyq00gyxb5us2wiznm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2Bu8ehC_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8jiyq00gyxb5us2wiznm.png" alt="code snippet" width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Additionally, if in your Network tab in the DOM you are seeing this in the payload:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LD9E9VuS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0yh1sg0d6ntl4zd3feo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LD9E9VuS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0yh1sg0d6ntl4zd3feo.png" alt="code snippet" width="540" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and this in the preview and response, &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EPtIB8z5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0b4kcugq79950kj10ix3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EPtIB8z5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0b4kcugq79950kj10ix3.png" alt="code snippet" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;then you have our image data getting through and simply need to handle how it renders on the front end.&lt;/p&gt;

&lt;p&gt;I hope this helps someone, somewhere with Active Storage. Like I said before, it is fairly easy to setup as long as all gem-files, like serializer, are installed properly and other dependencies are all in place too. This is a cool Rails add-on that makes image uploading and storage super easy.&lt;/p&gt;

&lt;p&gt;Good luck on your coding journey!   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Oyxgfvj3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbpx73yf3rgcdnrbywbl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Oyxgfvj3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbpx73yf3rgcdnrbywbl.gif" alt="clap" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building a Simple Rails API</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Sun, 03 Sep 2023 19:02:18 +0000</pubDate>
      <link>https://dev.to/tbraeck/building-a-simple-rails-api-4d2g</link>
      <guid>https://dev.to/tbraeck/building-a-simple-rails-api-4d2g</guid>
      <description>&lt;p&gt;I have really enjoyed learning about the Ruby on Rails language and using it to build my basic API was a fairly seamless process. Rails does many of the processes for you.  APIs serve as bridges between different software systems, enabling them to talk to each other and exchange information smoothly.&lt;/p&gt;

&lt;p&gt;In this guide, I will explore the process of building a basic API using Rails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting Up Your Rails Project&lt;/strong&gt;&lt;br&gt;
To create a new Rails project, open your terminal and run the following command:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails new YourApiName --api

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

&lt;/div&gt;



&lt;p&gt;The --api flag makes sure that you create a project designed for building APIs. After your project is generated, go to its folder:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd YourApiName

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

&lt;/div&gt;



&lt;p&gt;With your project set up, you're ready to start building your API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating Models and Migrations&lt;/strong&gt;&lt;br&gt;
In Rails, models are like blueprints for database tables. To make a new model along with a related migration, you can use the generate command. For example, in my own app I created a Drawing model by running:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
&lt;code&gt;rails generate model Drawing adjective:string noun:string verb:string adverb:string &lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;u&gt;This command generated both the model and a migration file that defines the database schema for the drawings table.&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Building Controllers&lt;/strong&gt;&lt;br&gt;
Endpoints are essential parts of any API. They specify how clients can interact with your application. In Rails, you can make endpoints by generating controllers and setting up routes. Here's an example of how I created an endpoint for listing all drawings:&lt;/p&gt;

&lt;p&gt;ruby&lt;br&gt;
&lt;code&gt;# app/controllers/drawings_controller.rb&lt;br&gt;
class DrawingsController &amp;lt; ApplicationController&lt;br&gt;
 def index&lt;br&gt;
    drawings = Drawing.all&lt;br&gt;
    render json: drawings, status: :ok&lt;br&gt;
  end&lt;br&gt;
end&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And my drawings config/routes.rb file:&lt;/p&gt;

&lt;p&gt;ruby&lt;br&gt;
&lt;code&gt;Rails.application.routes.draw do&lt;br&gt;
  resources :drawings, only: [:index, :show, :create, :update, :destroy]&lt;br&gt;
end&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, when I make a GET request to /drawings, my API will respond with a JSON array of products.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Serializers for Data Formatting&lt;/strong&gt;&lt;br&gt;
While Rails can automatically convert model data into JSON, serializers offer precise control over the output format. The Active Model Serializers gem is a commonly used tool for this.&lt;/p&gt;

&lt;p&gt;Here's how to set up a serializer for the Drawing model:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
&lt;code&gt;rails generate serializer Drawing&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This generates a serializer file for the Drawing model, allowing me to customize the JSON representation of drawings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication and Authorization&lt;/strong&gt;&lt;br&gt;
Securing your API is vital. Rails offers various authentication solutions, such as Devise for user authentication or JWT (JSON Web Tokens) for token-based authentication. Choose the method that best suits your project's requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error Handling Example&lt;/strong&gt;&lt;br&gt;
ruby&lt;br&gt;
`# app/controllers/drawings_controller.rb&lt;br&gt;
class DrawingController &amp;lt; ApplicationController&lt;br&gt;
  def create&lt;br&gt;
    user = User.find(params[:user_id])&lt;br&gt;
    drawing = user.drawings.create!(drawing_params)&lt;br&gt;
    render json: drawing, status: :created&lt;br&gt;
  end&lt;br&gt;
      render json: { errors: @drawing.errors.full_messages }, status: :unprocessable_entity&lt;br&gt;
    end&lt;br&gt;
  end&lt;/p&gt;

&lt;p&gt;# ...&lt;br&gt;
end`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenges Faced&lt;/strong&gt; &lt;br&gt;
I found most of the process to be fairly seamless, however I did encounter some confusion when dealing with multiple models, controllers, and routes all at the same time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Positive Aspects of Rails APIs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Building a robust API using Ruby on Rails is a fulfilling journey. By sticking to Rails conventions, like using serializers, adding authentication, and managing errors effectively, you can develop APIs that play a crucial role in modern web applications. &lt;/p&gt;

&lt;p&gt;I hope this simple guide to building a basic Rails API has been helpful. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating a Simple Backend with ActiveRecord and Sinatra</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Mon, 05 Jun 2023 17:47:12 +0000</pubDate>
      <link>https://dev.to/tbraeck/creating-a-simple-backend-with-activerecord-and-sinatra-mg9</link>
      <guid>https://dev.to/tbraeck/creating-a-simple-backend-with-activerecord-and-sinatra-mg9</guid>
      <description>&lt;p&gt;For my Phase 3 (Ruby) project through Flatirons School I needed to use an ActiveRecord backend and a REACT frontend for my app. The Ruby phase was an introduction to backend development and was overall a monster! However, I found working with the backend, creating tables, application controllers, seeding, etc. was a very interesting aspect of this whole process.&lt;/p&gt;

&lt;p&gt;I am interested in moving into the &lt;strong&gt;education tech industry&lt;/strong&gt; so I intended to create an app that would be a tool for educators or for learners- or both. I decided, because this project required a one to many relationship, that I would build an &lt;strong&gt;&lt;em&gt;educational resources app&lt;/em&gt;&lt;/strong&gt; for learners and educators to search. The landing page looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rb4piiPO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5jq5sm1rfci47oe28cm1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rb4piiPO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5jq5sm1rfci47oe28cm1.png" alt="Landing Page" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Users land on this page and can either click the "subjects" link or the button of the same name. It redirects to a list of seeded subject names such as "ART", "SCIENCE", or "THEATRE". These clickable subject names link to individual subject pages that list name, description, resources, urls, etc. &lt;/p&gt;

&lt;p&gt;For my backend I utilized Sinatra/ ActiveRecord. First, I created my migrations: &lt;strong&gt;create_resources&lt;/strong&gt; and &lt;strong&gt;create_subjects&lt;/strong&gt;. Within these migration files I built out a simple framework table for my database. Here is my create_resources example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateResources &amp;lt; ActiveRecord::Migration[6.1]
  def change
    create_table :resources do |t|

      t.string :name
      t.string :description
      t.text :url
      t.integer :subject_id
      t.timestamps

    end

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

&lt;/div&gt;



&lt;p&gt;The resources table will have columns for name, description, url, subject_id (the foreign key), and timestamps. Subjects will be the "one" and each subject will have "many" resources. I then created the models for each table. This is the resources model, which delineates the belongs_to relationship with the subjects model. The relationship of belongs_to and has_many determines the one-of-many interaction. Here is an example of what the two tables' keys look like and identifies the link between the two with the foreign key of "subject_id": &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cu6H9KDR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9v2my3ov75upennh2753.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cu6H9KDR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9v2my3ov75upennh2753.jpeg" alt="Active Record Tables Drawing" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once I finished my create_tables in the migrations I created models for each migration that encapsulate the relationship with inheritance from the ActiveRecord::base and describes the has_many or belongs_to relationship with the other table in my database. Here is an example from my code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Subject &amp;lt; ActiveRecord::Base 
has_many :resources, dependent: :destroy 

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

&lt;/div&gt;



&lt;p&gt;Next I worked on the application controller, which holds the keys to the backend/ frontend relationship and how the front end can link into the data in my database. This project is a basic CRUD application so I created some get requests for all "subjects" and singular "subjects" based on the subject_id(id) using GET requests. I did the same for "resources". Additionally I wanted users to be able to create a new resource, so used a POST request and the .create method for this request. &lt;/p&gt;

&lt;p&gt;I also wanted users to be able to use a DELETE request to destroy any resources they didn't not want on the app. If I were to make this app live I would restrict which data could be destroyed by users and which was protected data from my database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; Sinatra::Base
  set :default_content_type, 'application/json'


  get '/subjects' do
    subject = Subject.all.to_json(include: :resources)
      end

      get '/subjects/:id' do
    subject = Subject.find(params[:id])
    subject.to_json
    end

      post "/resources" do
   new_resource = Resource.create(
    name: params[:name],
    description: params[:description],
    url: params[:url],
    subject_id: params[:subject_id]
   )
   new_resource.to_json

end

      delete "/resources/:id" do
        deleteResource = Resource.find(params[:id])
        deleteResource.destroy
        # deleteResource.to_json
      end

      patch '/resources/:id' do
        resource = Resource.find_by(params[:id])
        resource.update(
          name: params[:name],
          description: params[:description],
          url: params[:url],
          subject_id: params[:subject_id]
    )
    resource.to_json
      end 


      get "/resources" do

        resource = Resource.all
        resource.to_json

      end

      get "/resources/:id" do

        resource = Resource.find(params[:id])
        resource.to_json

      end

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

&lt;/div&gt;



&lt;p&gt;I then created a simple seed file using the .create method on  "Subject" and on "Resource" instances. I only put some basic information in here because I felt like functionality was more important than content at this point. Again, if I made this a live app I would seed it with actual, viable information. &lt;/p&gt;

&lt;p&gt;Using the &lt;code&gt;rake db:migrate&lt;/code&gt; and then &lt;code&gt;rake db:seed&lt;/code&gt; I finalized my database migration and seeded the tables of the database. I then fired up the server using &lt;code&gt;rake server&lt;/code&gt; and tested the various requests out on POSTMAN before moving into my frontend using REACT.&lt;/p&gt;

&lt;p&gt;I found this whole process to be quite interesting, yet challenging, as I had not built a full-stack app before. It is actually very cool to try and puzzle out what backend relationships, requests, and data is needed to make a frontend meaningful. I found the most difficult part of this project to be the PATCH request, which I am still puzzling out as of now. &lt;/p&gt;

&lt;p&gt;Hope this helped someone along the line who might be struggling with basic ActiveRecord and Sinatra. Thanks&lt;/p&gt;

</description>
    </item>
    <item>
      <title>UseEffect and Where to Put State</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Tue, 28 Feb 2023 01:57:43 +0000</pubDate>
      <link>https://dev.to/tbraeck/useeffect-and-where-to-put-state-386i</link>
      <guid>https://dev.to/tbraeck/useeffect-and-where-to-put-state-386i</guid>
      <description>&lt;p&gt;Side-effects and state in React can be difficult topics to tackle on their own, but when I was faced with trying to wrap my brain around using both together for my code challenge recently- I felt kind of lost. &lt;/p&gt;

&lt;p&gt;However, now that I have had time to examine the code further and look through notes I took during my discussion with my assessor after the fact, I feel more confident in my understandings about the UseEffect Hook(side-effects) and the UseState Hook(state) in React.&lt;/p&gt;

&lt;p&gt;I will use the code from the code challenge as an example to &lt;strong&gt;explain when state should be utilized within a UseEffect Hook and when it should be outside UseEffect in the functional component.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The code challenge was to create a counter that, on mount, would begin counting up by 1 each second. There also needed to be 3 buttons: a play button, a reverse button, and a pause button. &lt;/p&gt;

&lt;p&gt;My initial instinct was to focus on the functionality of the buttons, creating an onClick event for each, a handler function that would deal with state and state value changes along the way. &lt;/p&gt;

&lt;p&gt;This can be seen with the code snippet below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
        &amp;lt;div&amp;gt;
            &amp;lt;p&amp;gt;{count}&amp;lt;/p&amp;gt;
            &amp;lt;button type='click' onClick={handlePlay}&amp;gt;Play&amp;lt;/button&amp;gt;
            &amp;lt;button type='click' onClick={handleReverse}&amp;gt;Reverse&amp;lt;/button&amp;gt;
            &amp;lt;button type='click' onClick={handlePause}&amp;gt;Pause&amp;lt;/button&amp;gt;

        &amp;lt;/div&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, the buttons needed this functionality and an event listener, but placing state in the correct place within the overall component was actually more important.&lt;/p&gt;

&lt;p&gt;The counter's functionality is in the UseEffect Hook, because it is a side-effect, and is happening asynchronously with the other functionality of the component. The interval starts after the initial rendering of the component and changes only when the state within the dependency array changes. Below is part of the UseEffect Hook content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
        let interval;

        if (isOn) {
            interval = setInterval(() =&amp;gt; {
                if (isReverse) {
                    setCount((count) =&amp;gt; count - 1)
                } else {
                    setCount((count) =&amp;gt; count + 1)
                }
            }, 1000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I knew that a state and setter function of something like "count, setCount" were needed for the counter=&amp;gt; which had an output on the client side as a &lt;/p&gt;
&lt;p&gt;  element. My initial inclination was to handle this and the other state outside of the useEffect- most likely in my handler functions- but that was very incorrect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const [count, setCount] = useState(0)
    const [isOn, setIsOn] = useState(true)
    const [isReverse, setIsReverse] = useState(false)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As seen above, the isOn and isReverse state are wrapped up in conditionals, and those two states are values within the dependency array- meaning when they change, the UseEffect fires again and runs through the conditionals until it lands on an argument that is true in that instance based on state at that time. &lt;/p&gt;

&lt;p&gt;The first one, 'isOn' is - being true it runs the setInterval, then if 'ifReverse' is true, the setCount setter function decrements the counter by one. The isOn and isReverse states truthiness determines which conditional is carried out- each holding the setCount setter function and either an increment or decrement of the count state(current state of count). &lt;/p&gt;

&lt;p&gt;This could not be handled outside the useEffect because the interval is asynchronous and a side-effect, so changes to it's behavior and state need to live in the UseEffect Hook with it and not in the "pure" function component that it lives in.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The current state of 'count' is actually determined by the state of isOn and isReverse within this nested conditional. No part of this state is needed outside of this Hook.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Also, the isOn and isReverse state values are both booleans (true/ false), so depending on the state of each of these (t/f) that will determine outside the UseEffect how those states can change based on an onClick event and the handler function that event calls.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function handlePlay() {
        setIsOn(true)
        setIsReverse(false)
    }

    function handleReverse() {
        setIsOn(true)
        setIsReverse(true)
    }

    function handlePause() {
        setIsOn(false)
    }

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

&lt;/div&gt;



&lt;p&gt;For instance, the handlePause function is fired when the button is clicked, the state of isOn is set to false and the counter is paused. When the reverse button is clicked it fires the handleReverse function that sets isOn to true and isReverse to true as well, which in the useEffect hook will fire the decrement code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if (isOn) {&lt;br&gt;
            interval = setInterval(() =&amp;gt; {&lt;br&gt;
                if (isReverse) {&lt;br&gt;
                    setCount((count) =&amp;gt; count - 1)&lt;br&gt;
                } else {&lt;br&gt;
                    setCount((count) =&amp;gt; count + 1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So, after all that, state should live in a useEffect if that states value is determined by the functions/ side-effects within the useEffect, but can be coupled with conditionals  and hard-wired state within handler functions to determine the path of the state within the conditionals in the useEffect. &lt;/p&gt;

&lt;p&gt;This was definitely a brain-teaser but I found it very interesting to look deeper into useState and useEffect in React. I had not done any code as complicated as this up until this point. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Phase 2: UseState Hook</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Sat, 04 Feb 2023 01:30:32 +0000</pubDate>
      <link>https://dev.to/tbraeck/phase-2-usestate-hook-35b1</link>
      <guid>https://dev.to/tbraeck/phase-2-usestate-hook-35b1</guid>
      <description>&lt;p&gt;UseState is a useful hook used to track the state of a function component. In general, it &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"refers to data or properties that need to be tracking in an application (w3schools.com/react/react_usestate.asp)."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Some common use cases are to keep track of information entered by a user in a form, toggle switches, buttons that fire other code that changes the state (conditional rendering), using a fetch (GET) request to obtain data from an API and store the response in state.&lt;/p&gt;

&lt;p&gt;The useState Hook is particularly helpful, in that it (along with other hooks) allows for much more readable code, whereas the use of class components can be very clunky and filled with boilerplate code that isn't necessary in Hooks. UseState returns an array because an array is more flexible than an object.&lt;/p&gt;

&lt;p&gt;Below I used the useState and useEffect Hooks for "ImagePage.js" for my Phase 2 project. &lt;/p&gt;

&lt;p&gt;In this snippet I have de-structured a variable "art" that will hold the state value. The "setArt" is the function that will change the value of the state "art". The useState([]) is setting the initial value of the state "art" as an empty array. The initial value of state can be,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"an object, an array, a boolean, or any other type you can imagine." &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then within the useEffect hook, which is wrapping the fetch request to my db.json, the data is used to set state for the art variable. This is passed down to the "ImageList.js" component as props and the .map method is used to iterate over all the objects in the array. Values from each object mapped are then passed down to the "ImageCard.js" component to delineate the final JSX code that will be used for the DOM render for each object. &lt;/p&gt;

&lt;p&gt;Holding this information in state is essential for smooth re-renders of pages when state changes, when a page is refreshed, etc. When a&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from "react";
import ImageList from './ImageList';
import Search from "./Search";
import NewArt from './NewArt';

function ImagePage() {
    const [art, setArt] = useState([])
    const [searchArt, setSearchArt] = useState('')

    useEffect(() =&amp;gt; {
        fetch(`http://localhost:8000/artwork`)
            .then((r) =&amp;gt; r.json())
            .then(artArray =&amp;gt; setArt(artArray))
    }, [])

    function addNewArt(myArt) {
        setArt([...art, myArt])
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another use case in my own project for useState is in the code below, which is in the "NewArt" component, which is essentially a form that a user can enter data into an create a new art image card on the art gallery page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function NewArt({ addNewArt }) {
    const [title, setTitle] = useState("")
    const [year, setYear] = useState("");
    const [price, setPrice] = useState(0.00)
    const [newImage, setNewImage] = useState("")


    function handleSubmit(e) {
        e.preventDefault();

        let newArt = {
            title: title,
            year: year,
            price: price,
            imageUrl: newImage
        }

        fetch(`http://localhost:8000/artwork`, {
            method: "POST",
            headers: {
                "Content-Type": 'application/json',
            },
            body: JSON.stringify(newArt)
        })
            .then((r) =&amp;gt; r.json())
            .then((myArt) =&amp;gt; addNewArt(myArt))
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Firstly, the function "addNewArt" is passed into this component as props, then called later in the component function. Next, the initial state is set for the new art which will be inputed by the user in the form fields (title, year, price, and imageURL), which are corresponding key/value pairs from the db.json which acts as my app's API. &lt;/p&gt;

&lt;p&gt;Another function "handleSubmit", which is used to prevent page reload on submit and to set the state values to the corresponding value in the db.json, all within a variable named "newArt".  Then a fetch(POST) is called which will use the prop of the function "addNewArt" from "ImagePage.js" to add the newly entered information into the state of 'art' or the array of art objects from the db.json. Thus, the useState hook helps to swiftly update state between multiple components in a concise manner.&lt;/p&gt;

&lt;p&gt;Below is more of the "NewArt.js" component code, specifically the form for entering new art data into the gallery space. It highlights the inline use of setting state with the onChange event handler here:&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;form className="form" onSubmit={handleSubmit}&amp;gt;
                &amp;lt;input className="formTitle" type="text" name="title" placeholder="New Art Title" value={title} onChange={(e) =&amp;gt; setTitle(e.target.value)} /&amp;gt;

                &amp;lt;input className="formYear" type="text" name="year" placeholder="Year Created" value={year} onChange={(e) =&amp;gt; setYear(e.target.value)} /&amp;gt;

                &amp;lt;input className="formPrice" type="number" name="price" step="0.1" placeholder="Price in $..." value={price} onChange={(e) =&amp;gt; setPrice(e.target.value)} /&amp;gt;

                &amp;lt;input className="formImage" type="text" name="image" placeholder="Image URL" value={newImage} onChange={(e) =&amp;gt; setNewImage(e.target.value)} /&amp;gt;


                &amp;lt;button className="formButton" type="submit"&amp;gt;Add Art&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each input in the form, which is controlled because of passing the correlated state variable into the value, then uses the onChange event handler. In the onChange the event is called as an argument and calls the setter function that corresponds to the given initialized state value- which then resets the state value to the "e.target.value" or what data is entered in the input field.&lt;/p&gt;

&lt;p&gt;This is repeated a few times in the form, as the same action and similar state updates are happening. Once these input values and their corresponding state is changed, and the submit button fires the "handleSubmit" function, the state variable is updated and the POST request happens, firing the DOM re-rendering and the db.json file to be updated.&lt;/p&gt;

&lt;p&gt;The useState hook is an essential addition to React as it helps to update state in different variables, strings, objects, array, etc. without all the unnecessary boilerplate code that came with using class components for this. Additionally it simply cleans up the code as a whole. I have found React Hooks to be much more user friendly and cleaner to work with and look at than what I have seen of React class components. I am hopeful that even better updates to Hooks will come about and React will be even easier to use.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Callback Functions</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Mon, 05 Dec 2022 03:19:48 +0000</pubDate>
      <link>https://dev.to/tbraeck/callback-functions-5a79</link>
      <guid>https://dev.to/tbraeck/callback-functions-5a79</guid>
      <description>&lt;p&gt;"A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action."&lt;br&gt;
&lt;a href="https://dev.tourl"&gt;-https://developer.mozilla.org/en-US/docs/Glossary/Callback_function&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Callback functions are an essential tool in modern web development used in both synchronous and asynchronous execution. Callback functions are used most commonly in asynchronous code execution, especially in response to an event, like a 'click' event or 'mouseover' event. &lt;/p&gt;

&lt;p&gt;Below is a simple example of how I used a callback function in my phase 1 final project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById('cutie').addEventListener("onmouseover", hideKitty);

function hideKitty() {
    document.getElementById("cutie").style.display = 'none';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First I used the 'getElementById' method to grab an html element from my html file called 'cutie'. This happened to be an &lt;a href="" class="article-body-image-wrapper"&gt;&lt;img&gt;&lt;/a&gt; element which the user would see on the client side. Once I grabbed the image I used 'addEventListener' as a function/ method to attach an event listener to the element.&lt;/p&gt;

&lt;p&gt;AddEventListener needs two arguments, the event type and a callback function. Mine is using an 'onmouseover' event type, meaning the user only needs to swipe the mouse over this image to invoke the function. Once the mouse over is initiated, it uses the callback function in the second argument- which in this case is hideKitty().&lt;/p&gt;

&lt;p&gt;Now that the event fired and invoked the "hideKitty" function, the code block inside of hideKitty executes. Again I used the getElementById()method to grab the image - I realize now I could have assigned a variable to this element in the global scope, but did not in this case a kept grabbing it in each code block. &lt;/p&gt;

&lt;p&gt;Using dot notation I used style.display to change how the image was displayed by assigning it a value of 'none'. So the image 'disappears' when the event fires and executes the callback of hideKitty. The 'showKitty' function uses a setTimeout() method to show the image again after 3000 milliseconds.  &lt;/p&gt;

&lt;p&gt;Another example in my code of a callback function is in here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fetchBtn = document.querySelector('#btnGet');
fetchBtn.addEventListener('click', getMovies);

function getMovies() {
    fetch(`http://localhost:3000/movies`)
        .then((response) =&amp;gt; response.json())
        .then((data) =&amp;gt; {
            let result = document.getElementById('result');

            result.innerText = '';

            data.forEach((movie) =&amp;gt; {
                result.innerHTML +=
                    `&amp;lt;p class="movieItem" &amp;gt;${movie.title} is a(n) ${movie.genre} movie that was released in ${movie.release}&amp;lt;/p&amp;gt;`
            })
        })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After capturing the button 'btnGet' with a querySelector, I added an eventListener() method, which takes in two arguments: the string of the event, such as 'click' and a callback function. In this case, I have my function getMovies as the callback in the eventListener. Once the click event is fired, it asynchronously executes the getMovies function and the code block within. In this case, it is a fetch GET request on a db.json local server that contains movie objects in the array.&lt;/p&gt;

&lt;p&gt;So once the 'click' event happens, the getMovies function is executed. The fetch GET request begins it's process. Reference to the break down of this fetch GET request is &lt;a href="https://dev.to/tbraeck/fetch-and-async-javascript-36po"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>FETCH AND ASYNC JAVASCRIPT</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Wed, 16 Nov 2022 00:54:12 +0000</pubDate>
      <link>https://dev.to/tbraeck/fetch-and-async-javascript-36po</link>
      <guid>https://dev.to/tbraeck/fetch-and-async-javascript-36po</guid>
      <description>&lt;p&gt;I have found async and fetch to be particularly frustrating to describe. I understand the process overall, but continue to not find the right words for the process. So here goes a description using my own fetch request in my Phase 1 Final Project. Fetch is an asycnhronous &lt;/p&gt;

&lt;p&gt;First I am grabbing my button &lt;code&gt;'btnGet'&lt;/code&gt; with the querySelector, then attaching a 'click' event to that button which executes the &lt;code&gt;'getMovies'&lt;/code&gt; function as a callback. Within the 'getMovies' function the fetch GET request is initiated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fetchBtn = document.querySelector('#btnGet');
fetchBtn.addEventListener('click', getMovies);

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

&lt;/div&gt;



&lt;p&gt;At that point the code block within the 'getMovies' function fires. First, the fetch method makes an GET http request to the live server/ db.json. A fetch GET request only requires one parameter, the URL of the API or live server you are sending the request to. &lt;/p&gt;

&lt;p&gt;That request instantly returns a promise object. The promise object can resolve as 3 types of statuses: pending, resolved, or error. When the promise object returns as resolved it is the entire HTTP response so the readable JSON body needs to be extracted. In the first .then the '(response)' is the value given to the returned/ resolved promise object. The JSON body is extracted from the promise object using the .json()method.&lt;br&gt;&lt;br&gt;
I used an arrow function and the .json as a callback function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getMovies() {
    fetch(`http://localhost:3000/movies`)
        .then((response) =&amp;gt; response.json())
        .then((data) =&amp;gt; {
            movies = data;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A second promise is returned and resolves with the result of the .json() method parsing the body as JSON.&lt;/p&gt;

&lt;p&gt;Then, in the second '.then' the new, readable data (parsed json array object) is used in some way through the new arrow function code block. I gave my new data the value of "data" to identify what was returned.  I want to take this data, which is movie objects with multiple key/ value pairs, and use that data in some way. Initially I 'console.log(data)' to see what is inside the returned value. What I find is an array of movie objects with different key/ value pairs.&lt;/p&gt;

&lt;p&gt;Now that I identified what is usable in the objects I want to use it in some way: &lt;br&gt;
Because the button "fetchBtn" is linked to a click event, I want use this event to print them to the DOM, client side via the &lt;code&gt;"result" &amp;lt;div&amp;gt;&lt;/code&gt;that is nested within my API SEARCH BUTTON &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Then I grabbed the 'result' &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;,using a document.getElementById and stored it in a variable named 'result,' so I could use it for my iterator later on. Using dot notation I then assign an empty string to result's textContent. This will allow each new element created by the forEach iteration to replace that empty string content on each pass through.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; let result = document.getElementById('result');

            result.textContent = '';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that I have a container to append to, the 'result' div, I want to use a forEach to iterate through the data returned from my GET request. I use the keyword 'data' to call on the data parameter from the fetch request, which will grab all of the array object. Then I use a forEach() method to iterate through all of the objects within the array. &lt;/p&gt;

&lt;p&gt;For each object I will append the innerHTML of the 'result' div with a &lt;/p&gt;
&lt;p&gt; element and use string interpolation to call on each individual movie's keys of title, genre, and release date. &lt;/p&gt;

&lt;p&gt;Within this code block the forEach iterates through each of the objects, inserts the new innerHTML with a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tag and prints all of the results to the client side with the &lt;code&gt;&amp;lt;div&amp;gt; id="apisearch".&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;           data.forEach((movie) =&amp;gt; {
                result.innerHTML +=
                    `&amp;lt;p class="movieItem" &amp;gt;${movie.title} is a(n) ${movie.genre} movie that was released in ${movie.release}&amp;lt;/p&amp;gt;`
            })
        })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I think writing this out helped me feel more comfortable explaining the fetch process. Once it was broken into parts, it made more sense and I could see each action taking place and why.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Phase 1 Project : Back to the 90's Site</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Sat, 08 Oct 2022 23:38:52 +0000</pubDate>
      <link>https://dev.to/tbraeck/phase-1-project-and-event-listeners-in-js-4g8a</link>
      <guid>https://dev.to/tbraeck/phase-1-project-and-event-listeners-in-js-4g8a</guid>
      <description>&lt;p&gt;Feeling a lot more confident about my coding skills. I have a long way to go, but doing my phase 1 project for my web development code camp. Doing it this way seems to make more sense- having a practical, "tangible" outcome for my efforts. I’ve had a lot of fun looking around at things, exploring, searching for solutions online, watching instructional videos, reading blogs about specific aspects of JS. &lt;/p&gt;

&lt;p&gt;The most interesting aspect for me has been dealing with event listeners and document queries. I feel like I learn better when I am able to apply it very quickly see you in front of me that kind of thing. Look forward to seeing what the reaction or the grade is for my phase one project.&lt;/p&gt;

&lt;p&gt;I found the keydown(arrow-key) event listener to be one of the most challenging coding pieces in this project. I had to do quite a bit of research to find code that made sense, that I could apply and adapt to my own site, and would work for the requirements of the project. I still feel a little confused about the parsing portion but will continue to investigate this aspect of the keydown event. Here is a snippet of my code for reference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 switch (e.key) {
        case "ArrowLeft":
            unicorn.style.left = parseInt(unicorn.style.left) - moveBy + 'px';
            break;
        case "ArrowRight":
            unicorn.style.left = parseInt(unicorn.style.left) + moveBy + 'px';
            break;
        case "ArrowUp":
            unicorn.style.top = parseInt(unicorn.style.top) - moveBy + 'px';
            break;
        case "ArrowDown":
            unicorn.style.top = parseInt(unicorn.style.top) + moveBy + 'px';
            break;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Through this process I have found that *&lt;em&gt;dot notation *&lt;/em&gt; makes the most sense when referencing, calling, and styling elements in my code. As with the unicorn moving event listener, referencing the style top/left made more sense in this way after having modified so much of the CSS by hand, piece by piece. &lt;/p&gt;

&lt;p&gt;This entire process has also highlighted how each piece is an integrated part of the other- for instance, though the HTML may seem like a disconnected document, it is connected to it's stylesheet and the Javascript in many fundamental ways. This example, one of many, can be seen with my API Search button that uses a fetch to a db.json file I created and creates new HTML elements that can be seen immediately by the user. &lt;/p&gt;

&lt;p&gt;Below is a code snippet of what I used to make this event happen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let result = document.getElementById("result")
            result.innerHTML = ''
            for (let i = 0; i &amp;lt; Math.min(movies.length, 5); i++) {
                let movie = movies[i]
                result.innerHTML +=
                    `&amp;lt;p class="movieItem" &amp;gt;${movie.title} is a(n) ${movie.genre} movie that was released in ${movie.release}&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of this was nested inside my fetch and after the response was converted.&lt;/p&gt;

&lt;p&gt;Additionally, I learned after finishing my project's first draft that I needed to have an API that utilized at least 5 objects with a minimum of 3 attribute each and was given the advice that I should use my iterator requirement with my API fetch. This was honestly a huge hurdle for me. I tried so many variations of this: trying to nest the &lt;strong&gt;forEach()&lt;/strong&gt; I had used before  in different areas, calling the functions in different areas, trying to figure out exactly where the disconnect was happening. I leaned on debugger and console.log quite a bit. &lt;/p&gt;

&lt;p&gt;In the end it took the form of what I showed above- plus the fetch and event listener.&lt;/p&gt;

&lt;p&gt;Another interesting aspect of this project was fiddling with the stylesheet. This is meaningful to me because I am an art teacher/ visual artist, so being able to see changes immediately to what I have coded has helped me more and more along the way. Now I want to make my work more aesthetically beautiful and find new tricks like flex-boxes to improve my own work speed and efficiency.&lt;/p&gt;

&lt;p&gt;Here is a small snippet of one element's styling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* KITTY IMG */
#cutie {
    position: absolute;
    padding: 0;
    left: 1250px;
    top: 1000px;
    z-index: 2;
    border: 5px solid #000000;
    padding: 3px;
    margin: 0px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I know that later, many times the styling comes in packages or there are more simplified ways to style elements of a project, but I am enjoying doing the long-hand right now so I can be stronger later on.&lt;/p&gt;

&lt;p&gt;This project gave me a much more concrete outcome for what I have been learning so far. Along the way I have found it quite challenging to do some of the labs, as the final outcome is not my own or tangible overall- that doesn't mean the process isn't valuable, just how I am feelings about the learning so far. &lt;/p&gt;

&lt;p&gt;Overall, I feel like creating this project was the biggest and most fulfilling challenge for me so far with the Flatirons software engineering program. I say this but know I have a long way to go...&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Backwards to go forward</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Sat, 24 Sep 2022 03:31:06 +0000</pubDate>
      <link>https://dev.to/tbraeck/backwards-to-go-forward-3hef</link>
      <guid>https://dev.to/tbraeck/backwards-to-go-forward-3hef</guid>
      <description>&lt;p&gt;I was feeling overwhelmed the last few days with my dev journey- like I was kind of drowning in information and lost. So I decided to start from the beginning again, the basics and fundamentals of JS to get me back on track.&lt;/p&gt;

&lt;p&gt;I already feel much better, tackling early concepts like array, basic functions and callbacks, and other beginner stuff. I will succeed at this and need to take on each step like this- one bite at a time with solid knowledge to back it all up.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Being lost but not gone</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Tue, 20 Sep 2022 15:13:59 +0000</pubDate>
      <link>https://dev.to/tbraeck/being-lost-but-not-gone-47ml</link>
      <guid>https://dev.to/tbraeck/being-lost-but-not-gone-47ml</guid>
      <description>&lt;p&gt;About 3 weeks into my Dev program. Feeling generally positive and feeling kind of lost most of the time too. When I think I have a concept- have gone through a lecture or a video- I get to the applied portion of the content and feel a fairly confused. &lt;/p&gt;

&lt;p&gt;I know this is like learning a new language- not going to be easy and I need to immerse myself- but I want some break throughs. I want more of those "aha" moments, and know they are what will push me again and again to find my way around the obstacle or to problem solve my way out of a coding corner. &lt;/p&gt;

&lt;p&gt;I will not quit. Just needed a moment to reflect and reassess. Tomorrow will bring new insights and ideas, more clarity and everything  will make sense...&lt;/p&gt;

</description>
    </item>
    <item>
      <title>First Blog Post as a newbie</title>
      <dc:creator>Tate Braeckel</dc:creator>
      <pubDate>Mon, 08 Aug 2022 16:33:14 +0000</pubDate>
      <link>https://dev.to/tbraeck/first-blog-post-as-a-newbie-534c</link>
      <guid>https://dev.to/tbraeck/first-blog-post-as-a-newbie-534c</guid>
      <description>&lt;p&gt;This is my first post as a newbie web developer. I start my online courses with Flatirons school at the end of August. I feel kind of anxious about the whole process but am also super excited to be learning something completely new, doing this for myself and my family, and for what it will all look like down the road....&lt;/p&gt;

&lt;p&gt;Right now I am a beginner at HTML, CSS, and JavaScript. I feel pretty strong maneuvering HTML and CSS but need a-lot of work with JavaScript. I have been fiddling with HTML and CSS on my wife's Shopify page and that has felt pretty amazing actually understanding what I'm doing- mostly. &lt;/p&gt;

&lt;p&gt;So to future me...I promise to stay dedicated, curious, and excited: for me, my family, my future. &lt;/p&gt;

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