<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: nadia4206</title>
    <description>The latest articles on Forem by nadia4206 (@nadia4206).</description>
    <link>https://forem.com/nadia4206</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F994874%2Fb0cfa31d-5006-4749-acd8-e0861897cf8f.png</url>
      <title>Forem: nadia4206</title>
      <link>https://forem.com/nadia4206</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nadia4206"/>
    <language>en</language>
    <item>
      <title>Work smarter, not harder (how to use the "rails g resource" command)</title>
      <dc:creator>nadia4206</dc:creator>
      <pubDate>Mon, 06 Mar 2023 13:44:30 +0000</pubDate>
      <link>https://forem.com/nadia4206/work-smarter-not-harder-how-to-use-the-rails-g-resource-command-53f6</link>
      <guid>https://forem.com/nadia4206/work-smarter-not-harder-how-to-use-the-rails-g-resource-command-53f6</guid>
      <description>&lt;p&gt;Ruby on Rails is a popular web application framework that simplifies web development by providing a set of conventions and tools. One of the most powerful features of Rails is the ability to generate code quickly using the built-in generators. In this blog, we will focus on the &lt;code&gt;rails g resource&lt;/code&gt; command, which generates a set of files for a new resource in your application.&lt;/p&gt;

&lt;p&gt;A resource in Rails is a representation of a model, controller, and views that work together to provide CRUD (Create, Read, Update, Delete) functionality for a specific type of object. For example, if you were building a blog application, you might have a resource for posts, which would include a Post model, a Posts controller, and views for displaying, editing, and creating posts.&lt;/p&gt;

&lt;p&gt;To use the &lt;code&gt;rails g resource&lt;/code&gt; command, you'll need to open up your terminal and navigate to the root directory of your Rails application. From there, you can run the command followed by the name of your resource, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails g resource Post
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also define the details of your table directly in the terminal. The type "string" is inferred, so those datatypes do not need to be defined:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails g resource Post title content author likes:integer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will generate a set of files for the Post resource, including:&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;migration&lt;/strong&gt; file: This file is used to create the database table for the Post model. The migration includes columns for the various attributes of a post, such as title, content, author, and likes.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;model&lt;/strong&gt; file: This file defines the Post class, which inherits from &lt;code&gt;ActiveRecord::Base&lt;/code&gt;. It also includes validations and associations with other models, if applicable.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;controller&lt;/strong&gt; file: This file defines the PostsController class, which handles HTTP requests and responses for the Post resource. It includes methods for creating, reading, updating, and deleting posts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Views&lt;/strong&gt;: The generator creates views for the various actions of the PostsController, such as index, show, create, update, and destroy. &lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;serializer&lt;/strong&gt; file: &lt;em&gt;if you have the serializer gem installed&lt;/em&gt;, the &lt;code&gt;rails g resource&lt;/code&gt; command will also generate a corresponding serializer file.&lt;/p&gt;

&lt;p&gt;Once the generator has finished running, you can run migrations to create the Post table in your database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! You now have a fully functional resource for Posts in your Rails application. Of course, you'll need to customize the generated files to fit your specific requirements, but this generator can save you a lot of time and effort in setting up the basic structure of your application.&lt;/p&gt;

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

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>beginners</category>
    </item>
    <item>
      <title>💎 How to use the Ruby Faker Gem 💎</title>
      <dc:creator>nadia4206</dc:creator>
      <pubDate>Mon, 13 Feb 2023 14:00:53 +0000</pubDate>
      <link>https://forem.com/nadia4206/how-to-use-the-ruby-faker-gem-2il3</link>
      <guid>https://forem.com/nadia4206/how-to-use-the-ruby-faker-gem-2il3</guid>
      <description>&lt;p&gt;What is the Ruby Faker Gem? It's a handy little tool that allows you to be able to easily create as much dummy data as you need to test out your methods. You can use this blog as a beginners guide to using Faker!&lt;/p&gt;

&lt;p&gt;To start, add the faker gem to your project by running "gem install faker" in your project terminal. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb85unhku8cqvnual947m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb85unhku8cqvnual947m.png" alt="Image description" width="578" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Be sure to check that your Gemfile has a line for the faker gem (i.e. &lt;code&gt;gem "faker"&lt;/code&gt;). If it doesn't, be sure to add it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzj9y324kdfzimm34fc7d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzj9y324kdfzimm34fc7d.png" alt="Image description" width="578" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add "require 'faker'" to the top of your seeds.rb file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffuwwel6ufhgy1ha20exw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffuwwel6ufhgy1ha20exw.png" alt="Image description" width="578" height="147"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, you can use the &lt;a href="https://github.com/faker-ruby/faker" rel="noopener noreferrer"&gt;handy dandy faker documentation&lt;/a&gt; to guide you through creating your data. &lt;/p&gt;

&lt;p&gt;Here's how I set up data using Faker for a table called "Chefs":&lt;/p&gt;

&lt;p&gt;In my Chefs table, I have 3 fields: &lt;code&gt;first_name&lt;/code&gt;, &lt;code&gt;last_name&lt;/code&gt;, and &lt;code&gt;current_restaurant&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;To get a Faker generated &lt;code&gt;first_name&lt;/code&gt;, I checked the &lt;a href="https://github.com/faker-ruby/faker" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;, found the "Name" category, and saw there was an option to generate a first name: &lt;code&gt;Faker::Name.first_name&lt;/code&gt;. You can do pretty much the same thing to generate a last name by using: &lt;code&gt;Faker:: Name.last_name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Finally, for &lt;code&gt;current_restaurant&lt;/code&gt; I searched the documentation and found there is a Faker category for Restaurant! I go ahead and use &lt;code&gt;Faker::Restaurant.name&lt;/code&gt; for the &lt;code&gt;current_restaurant&lt;/code&gt; field:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ealljeaypynplvmg60m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ealljeaypynplvmg60m.png" alt="Image description" width="470" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, you can seed your data like you normally would (&lt;code&gt;rake db:seed&lt;/code&gt;). Once your data is done seeding, you'll see randomly generated first names, last names, and current restaurants in your database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93doz7n1hh9gfrk7vtq2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93doz7n1hh9gfrk7vtq2.png" alt="Image description" width="484" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pretty nifty!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>PUT v PATCH</title>
      <dc:creator>nadia4206</dc:creator>
      <pubDate>Thu, 19 Jan 2023 20:23:03 +0000</pubDate>
      <link>https://forem.com/nadia4206/put-v-patch-1fbd</link>
      <guid>https://forem.com/nadia4206/put-v-patch-1fbd</guid>
      <description>&lt;p&gt;Did you know that according to the &lt;a href="https://www.iana.org/assignments/http-methods/http-methods.xhtml"&gt;Internet Assigned Numbers Authority&lt;/a&gt;, there are &lt;strong&gt;39&lt;/strong&gt; different HTTP methods?? 🤯 As a newcomer to coding, I've only been working with a handful of the more common methods like GET, POST, PATCH, and DELETE. &lt;/p&gt;

&lt;p&gt;Recently, I learned about the PUT method. Similar to PATCH, PUT updates data, but there are some important differences between the two. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PUT&lt;/strong&gt; is used to update an entity's data completely. PUT overwrites the entire entity if it already exists, and creates a new resource if it doesn't. What this means is that when working with PUT, you will need to send details for the entire resource, or you will replace the resource only with what you've sent in your PUT request. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PATCH&lt;/strong&gt; applies a partial update to the resource, meaning you only need to send the data that you want to update. After sending the PATCH request, that specific piece of information will update, without replacing the entire entity. &lt;/p&gt;

&lt;p&gt;What does this look like IRL? &lt;/p&gt;

&lt;p&gt;Let's say we have a business that offers customizable meal plans. Below is the data we use to update specific meal plans:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
     "protein": "Flank Steak",
     "vegetable": "Asparagus",
     "starch": "Brown Rice",
     "dessert": "Chocolate Chip Cookie"
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I need to update the starch on this meal from Brown Rice to Sweet Potatoes. If I use a PUT request and &lt;strong&gt;only&lt;/strong&gt; send &lt;code&gt;"starch": "Sweet Potatoes"&lt;/code&gt;, without the other elements, this is what I'll get in return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "starch": "Sweet Potatoes"
}

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

&lt;/div&gt;



&lt;p&gt;If I use a PATCH request only sending &lt;code&gt;"starch": "Sweet Potatoes"&lt;/code&gt;, the response would return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; {
     "protein": "Flank Steak",
     "vegetable": "Asparagus",
     "starch": "Sweet Potatoes",
     "dessert": "Chocolate Chip Cookie"
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using PATCH, we could also add another item to the meal, like a beverage, by sending only &lt;code&gt;"beverage": "Orange Cranberry Spritzer"&lt;/code&gt;. This will add a "beverage" element to the object instead of replacing the entire entity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; {
     "protein": "Flank Steak",
     "vegetable": "Asparagus",
     "starch": "Sweet Potatoes",
     "dessert": "Chocolate Chip Cookie",
     "beverage": "Orange Cranberry Spritzer"
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Cited Source: &lt;a href="https://rapidapi.com/blog/put-vs-patch/"&gt;https://rapidapi.com/blog/put-vs-patch/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>What is the difference between .textContent, .innerText, and .innerHTML?</title>
      <dc:creator>nadia4206</dc:creator>
      <pubDate>Thu, 22 Dec 2022 20:53:45 +0000</pubDate>
      <link>https://forem.com/nadia4206/what-is-the-difference-between-textcontent-innertext-and-innerhtml-38io</link>
      <guid>https://forem.com/nadia4206/what-is-the-difference-between-textcontent-innertext-and-innerhtml-38io</guid>
      <description>&lt;p&gt;Hi! My name is Nadia and I'm currently a student enrolled in the Software Engineering program at Flatiron School. &lt;/p&gt;

&lt;p&gt;I just started a few weeks ago and it's been a whirlwind! So much information to digest! &lt;/p&gt;

&lt;p&gt;One thing I've noticed is that there are so many different ways to accomplish one goal. &lt;/p&gt;

&lt;p&gt;For example, to "set" or "retrieve" the text content of an element, you can use either &lt;code&gt;.textContent&lt;/code&gt;, &lt;code&gt;.innerText&lt;/code&gt;, or &lt;code&gt;.innerHTML&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Builtin.com has a great article that breaks down the differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"&lt;code&gt;.innerHTML&lt;/code&gt; allows you to see exactly what is in the HTML markup contained within a string."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What this means is that when you call &lt;code&gt;.innerHTML&lt;/code&gt; it will return the string and any HTML markup contained within the string. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;"&lt;code&gt;.innerText&lt;/code&gt; approximates the 'rendered' text content of a node and is aware of styling and CSS."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"&lt;code&gt;.textContent&lt;/code&gt; retrieves and sets the content of the tag as plain text."&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At first glance, it seems like &lt;code&gt;.innerText&lt;/code&gt; and &lt;code&gt;.textContent&lt;/code&gt; are exactly the same. The author of this article goes on to explain that the difference is that &lt;code&gt;.innerText&lt;/code&gt; is aware of the rendered appearance while &lt;code&gt;.textContent&lt;/code&gt; is not. &lt;/p&gt;

&lt;p&gt;What you'll want to use depends on what you want to be able to see! &lt;/p&gt;

&lt;p&gt;Referenced Article: &lt;a href="https://builtin.com/software-engineering-perspectives/innerhtml-vs-innertext" rel="noopener noreferrer"&gt;https://builtin.com/software-engineering-perspectives/innerhtml-vs-innertext&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gratitude</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
