<?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: Kristina Hodges (Voroteliak)</title>
    <description>The latest articles on Forem by Kristina Hodges (Voroteliak) (@chrispavla).</description>
    <link>https://forem.com/chrispavla</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%2F902881%2F633ce3f9-6a76-43c8-bfcb-d4057b17e524.jpeg</url>
      <title>Forem: Kristina Hodges (Voroteliak)</title>
      <link>https://forem.com/chrispavla</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chrispavla"/>
    <language>en</language>
    <item>
      <title>Create a responsive map with Mapbox in React</title>
      <dc:creator>Kristina Hodges (Voroteliak)</dc:creator>
      <pubDate>Wed, 02 Nov 2022 17:39:43 +0000</pubDate>
      <link>https://forem.com/chrispavla/create-a-responsive-map-with-mapbox-in-react-1ed7</link>
      <guid>https://forem.com/chrispavla/create-a-responsive-map-with-mapbox-in-react-1ed7</guid>
      <description>&lt;p&gt;In one of my personal projects I wanted to implement a feature that would allow users to pin their travel destinations using dynamic map, with a React frontend and Ruby on Rails for the backend.&lt;/p&gt;

&lt;p&gt;Let's dive in and look at how to create a fully responsive map with custom Markers using Mapbox in our React application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SETTING UP&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using Mapbox requires an &lt;strong&gt;access token&lt;/strong&gt;. Let's see how you can obtain your own Mapbox API key (it's super easy)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 1&lt;/em&gt;&lt;br&gt;
In order to be able to use MapBox, we need to create a free Mapbox account to get an accessToken to be able to use the map on your website.&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://www.mapbox.com/signup/" rel="noopener noreferrer"&gt;https://www.mapbox.com/signup/&lt;/a&gt; and create a Mapbox account. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 2&lt;/em&gt;&lt;br&gt;
In order to get the token you will need to provide your billing information, but don't worry, Mapbox offers you &lt;strong&gt;50,000 map loads free&lt;/strong&gt; per month, which is very generous for doing all the local development as well as publishing small personal projects.&lt;/p&gt;

&lt;p&gt;Create a new token using the blue button as below after signup, then copy it to the clipboard by clicking on the button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fgwt51l43z27ljmf7txts.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fgwt51l43z27ljmf7txts.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F76p4r1yzixg0ookozgzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F76p4r1yzixg0ookozgzg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 3.&lt;/em&gt; &lt;br&gt;
Make sure you protect your token! Never post your token anywhere, or leave it unprotected. You don't want anyone taking advantage of your token. &lt;br&gt;
To &lt;strong&gt;protect your token&lt;/strong&gt;, in the root of your project, create an .env.local file and add your token to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* .env.local */
REACT_APP_MAPBOX_ACCESS_TOKEN=YOUR_TOKEN_HERE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;INSTALLATION&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Using react-map-gl requires react &amp;gt;= 16.3.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In order to include MapBox into our React application, we will use react-map-gl, a set of React components created by engineers at Uber for Mapbox GL JS that can be easily included in our React application.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save react-map-gl mapbox-gl&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STYLING&lt;/strong&gt;&lt;br&gt;
The current Mapbox-gl release requires its stylesheet to be included at all times. The marker, popup and navigation components in react-map-gl also need the stylesheet to work properly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.js
import 'mapbox-gl/dist/mapbox-gl.css';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Time to DISPLAY MAP&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To add a map, first we need to import the map into our component, in my case it is src/Map.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ReactMapGL from "react-map-gl";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we will initialize default state for our map with the required coordinates: latitude, longitude, the size of the map(width, height), and zoom for the viewport.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const [viewport, setViewport] = useState({
    latitude: 50.5821,
    longitude: 7.0216,
    width: "80vw",
    height: "80vh",
    zoom: 3,
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These values will all change as our user interacts with the map.&lt;/p&gt;

&lt;p&gt;We are now ready to &lt;strong&gt;setup the MapGL component&lt;/strong&gt; in the render method&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;ReactMapGL
        {...viewport}
        mapboxApiAccessToken={process.env.REACT_APP_MAPBOX_TOKEN}
        mapStyle="mapbox://styles/cl9fv02ny000h14o0576ux3mj"
        onViewportChange={(viewport) =&amp;gt; {
          setViewport(viewport);
        }}
&amp;gt;
&amp;lt;/ReactMapGl&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;mapStyle is used to select the type of map you want to render. You can create your own style through Mapbox studio or pick any of the predefined styles, copy the map style link and insert your mapStyle&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;em&gt;onViewportChange is required in order to update viewport with new coordinates when a user interacts with the map&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Save your changes.&lt;/strong&gt; Now you should be able to see your interactive new Mapbox map!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Now, let's add some Place Markers on the map!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we need to import Marker at the top of our component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ReactMapGL, { Marker } from "react-map-gl";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fun part is, you can you any icon or image as your Markers, I found the icon I want to use and imported it as well&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import marker from "../assets/marker.png";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My custom &lt;em&gt;backend&lt;/em&gt; holds &lt;strong&gt;locations&lt;/strong&gt; data, which contains longitude and latitude, and I want to create a marker for each location.&lt;/p&gt;

&lt;p&gt;The render below is modified to include the marker display in the form of a Pin Icon based on the locations data.&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;ReactMapGL
        {...viewport}
        mapboxApiAccessToken={process.env.REACT_APP_MAPBOX_TOKEN}
        mapStyle="mapbox://styles/cl9fv02ny000h14o0576ux3mj"
        onViewportChange={(viewport) =&amp;gt; {
          setViewport(viewport);
        }}
      &amp;gt;
        {locations.map((location) =&amp;gt; (
          &amp;lt;Marker
            key={location.id}
            latitude={location.latitude}
            longitude={location.longitude}
          &amp;gt;
              &amp;lt;img src={marker} alt="place marker" /&amp;gt;
          &amp;lt;/Marker&amp;gt;
        ))}
&amp;lt;/ReactMapGL&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...and just like that we have our &lt;strong&gt;beautiful interactive map with custom markers&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fhnjkeqd61ij34upj9kal.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fhnjkeqd61ij34upj9kal.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We looked at how to display a map with markers at specific coordinates in a React Application, using MapBox GL JS library through the components provided by the react-map-gl. This library provides a lot of functionalities and styling around maps and can be explored further depending on your interest and requirements. &lt;/p&gt;

&lt;p&gt;Next time we will look at how to display &lt;strong&gt;Popups&lt;/strong&gt;, &lt;strong&gt;navigation control&lt;/strong&gt; and display a &lt;strong&gt;sidebar with coordinates&lt;/strong&gt; of the map and its zoom level.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The art of handling errors with rescue_from and Rails</title>
      <dc:creator>Kristina Hodges (Voroteliak)</dc:creator>
      <pubDate>Tue, 11 Oct 2022 13:07:59 +0000</pubDate>
      <link>https://forem.com/chrispavla/the-art-of-handling-errors-with-rescuefrom-and-rails-4nel</link>
      <guid>https://forem.com/chrispavla/the-art-of-handling-errors-with-rescuefrom-and-rails-4nel</guid>
      <description>&lt;p&gt;In the Ruby programming language, exceptions are a common feature. About 30 different exception subclasses are defined in the Ruby standard library, some of which have their subclasses. &lt;/p&gt;

&lt;p&gt;Let's go over how to use rescue exceptions in ruby and how to handle them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Errors Are Actually Good&lt;/strong&gt;&lt;br&gt;
A quick preface before we go any deeper: errors should be embraced during the development stage of your code. While you certainly don’t want a user to hit an error page, embracing errors as a normal part of software development is a healthy mindset to get into.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is an Exception?&lt;/strong&gt;&lt;br&gt;
An exception represents an error condition in a program. Exceptions are a mechanism for stopping a program's execution. Unhandled exceptions cause Ruby programs to crash.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Exception Handling?&lt;/strong&gt;&lt;br&gt;
Software systems are typically prone to errors. Exceptions are more likely to occur in systems that include human involvement because they attract errors on numerous levels.&lt;/p&gt;

&lt;p&gt;Syntactical errors, network errors, form input errors, invalid authentication errors, and so on are all examples of errors. These can damage user experience and potentially emerge as security loopholes, allowing attackers to compromise the system if not addressed.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Exception handling prevents system failures and saves the user from annoying error messages.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When an error condition occurs, the programming language usually compels the program to terminate, and control of the program is lost. Exception handling allows you to maintain control and respond to what occurs after an error has occurred.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This offers you some flexibility to make changes, such as displaying friendly error messages, releasing resources, or quickly redirecting the user to a relevant website.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rescue_from and Rails&lt;/strong&gt;&lt;br&gt;
Starting from the release 2.0, Rails provides a clean way to rescue exceptions in a controller, mapping specific error classes to corresponding handlers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rescue_from&lt;/strong&gt; receives a series of exception classes or class names, and a trailing :with option with the name of a method or a Proc object to be called to handle them. Alternatively a block can be given.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let's see an example.&lt;/em&gt; A call to ActiveRecord#find raises an ActiveRecord::RecordNotFound exception when the record passed as parameter doesn't exist. Assuming you want to display a nice error message, you need to rescue the exception in each action where a find call is performed.&lt;/p&gt;

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

&lt;p&gt;This approach leads to lot of code duplication if you count the number of find calls for each action per model. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;rescue_from method&lt;/strong&gt; is exactly the &lt;strong&gt;solution&lt;/strong&gt; we are looking for. Instead of catching the exception at action-level, we instruct the controller to rescue all the ActiveRecord::RecordNotFound errors and forward the exception to the proper handler.&lt;/p&gt;

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

&lt;p&gt;Voilà! Now you have much cleaner code and displaying friendly error messages :)&lt;/p&gt;

&lt;p&gt;P.S. Example of React side finished error handling product&lt;/p&gt;

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

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Building a Sinatra API backend with Active Record Associations</title>
      <dc:creator>Kristina Hodges (Voroteliak)</dc:creator>
      <pubDate>Fri, 16 Sep 2022 16:50:31 +0000</pubDate>
      <link>https://forem.com/chrispavla/building-a-sinatra-api-backend-with-active-record-associations-326p</link>
      <guid>https://forem.com/chrispavla/building-a-sinatra-api-backend-with-active-record-associations-326p</guid>
      <description>&lt;p&gt;In this blogpost let's go step by step and build your own Sinatra API backend that uses Active Record to access and persist data in a database&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ActiveRecord and Sinatra&lt;/strong&gt;&lt;br&gt;
ActiveRecord can be used in conjunction with Sinatra to handle creating the data tables used to store the data being asked for by HTTP requests. &lt;/p&gt;

&lt;p&gt;ActiveRecord is the model portion of MVC (model-view-controller) which is in charge of creating objects whose data is needed to persist within a SQL database. It helps developers create database migrations with methods put in place with a little bit of metaprogramming magic! &lt;/p&gt;

&lt;p&gt;We build our data tables and data models out with ActiveRecord, and then control what data we are querying our database for within our Sinatra routes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1. Have a clear idea of what you want to create and what it'll look like&lt;/strong&gt;&lt;br&gt;
Try answering questions like “how many models am I going to have? How many views?” This should be clear before you move on and get started&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 2. Create the necessary models for your project.&lt;/strong&gt;&lt;br&gt;
Think through your project, in terms of how many relations you’re going to have. You have to understand the type of relationship your tables will have, e.g., one-to-one, one-to-many, or many-to-many.&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;Step 3. Create a migration to create the Users table with ActiveRecord&lt;/strong&gt;&lt;br&gt;
Run the following command to create migrations for each model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle exec rake db:create_migration NAME=create_users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The outcome should be timestamped files in the db&amp;gt;migrate folder: (for each model, you’ll perform its migration, one at a time.)&lt;/p&gt;

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

&lt;p&gt;Inside each of the timestamped files, you’ll find an empty change method where you are to list the table attributes (columns) and the datatypes for each column&lt;/p&gt;

&lt;p&gt;After filling in the attributes, you’ll get:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 3. Run migrations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Migrations will be done using the command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Your generated schema should look like this:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step 4. Seeding data to your DB&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the seeds.rb file, you’ll have to specify how you want to seed your data.&lt;/p&gt;

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

&lt;p&gt;Use the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle exec rake db:seed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5. Finally, using Sinatra’s built-in routing methods, we can set up a response to fetch request from the front end.&lt;/strong&gt; &lt;/p&gt;

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

&lt;p&gt;This will return a list of “jsonified” Users by calling the .all and .order methods on a User class, which holds all of the User instances. &lt;/p&gt;

&lt;p&gt;On the front end, if you are using a React front end, we can now use the users data we just fetched from the database and set a stateful variable equal to it. &lt;/p&gt;

&lt;p&gt;From there, however we decide to display the data is up to us!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Breakdown of Declarative vs. Imperative programming</title>
      <dc:creator>Kristina Hodges (Voroteliak)</dc:creator>
      <pubDate>Fri, 26 Aug 2022 01:28:00 +0000</pubDate>
      <link>https://forem.com/chrispavla/breakdown-of-declarative-vs-imperative-programming-463d</link>
      <guid>https://forem.com/chrispavla/breakdown-of-declarative-vs-imperative-programming-463d</guid>
      <description>&lt;p&gt;JavaScript is an outstanding programming language that allows you to write code in different paradigms or combine them into a 'multi-paradigmatic' approach.&lt;/p&gt;

&lt;p&gt;But what does that even mean? &lt;/p&gt;

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

&lt;p&gt;A programming paradigm is an approach or a style of writing code. Most of the modern programming languages fall into two general paradigms: &lt;strong&gt;imperative&lt;/strong&gt; and &lt;strong&gt;declarative&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;So what is the difference?&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Declarative&lt;/strong&gt; programming is when you say &lt;strong&gt;what&lt;/strong&gt; you want, and &lt;strong&gt;imperative&lt;/strong&gt; language is when you say &lt;strong&gt;how&lt;/strong&gt; to get what you want.&lt;/p&gt;

&lt;p&gt;I like to think about it as the &lt;em&gt;process of ordering a meal&lt;/em&gt;. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Imperative&lt;/strong&gt; goes to a Subway restaurant and wants to order a sandwich. For that he chooses: size, type of bread, meat, veggies, cheese, extra ingredients, and a sauce, he also tells to heat up his bread. The waiter delivers &lt;strong&gt;exactly what&lt;/strong&gt; he asked for.&lt;/p&gt;

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

&lt;p&gt;On the other hand, &lt;strong&gt;Declarative&lt;/strong&gt; goes to McDonald's and tells that he wants a double cheeseburger. Grabs the burger.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What is imperative programming?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imperative programming is the oldest and most basic programming approach. Within the imperative paradigm, code describes a step-by-step process for a program’s execution.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Examples of imperative programming languages include:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Java&lt;/li&gt;
&lt;li&gt;C&lt;/li&gt;
&lt;li&gt;Pascal&lt;/li&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;Ruby&lt;/li&gt;
&lt;li&gt;Fortran&lt;/li&gt;
&lt;li&gt;PHP&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What is declarative programming?&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
In contrast with imperative programming, declarative programming describes what you want the program to achieve rather than how it should run.&lt;/p&gt;

&lt;p&gt;In other words, within the declarative paradigm, you define the results you want a program to accomplish without describing its control flow.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Examples of declarative programming languages include:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SQL&lt;/li&gt;
&lt;li&gt;Miranda&lt;/li&gt;
&lt;li&gt;Prolog&lt;/li&gt;
&lt;li&gt;Lisp&lt;/li&gt;
&lt;li&gt;Many markup languages (e.g., HTML)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let's look at some code:&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Declarative programming describes what you’re trying to accomplish without defining how to do it.&lt;/p&gt;

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

&lt;p&gt;For the first example which is an Imperative programming approach, it usually has more lines code, that’s the very obvious difference. &lt;br&gt;
Another is, it explicitly follows a step-by-step instruction to get the even numbers from the array. &lt;br&gt;
While in the declarative programming approach, it leverages an existing function, which is filter.&lt;/p&gt;




&lt;p&gt;The differences are subtle, but hopefully you have a better background to understand them from now.&lt;/p&gt;

&lt;p&gt;With experience, you are able to learn which situations call for which programming paradigms!&lt;/p&gt;

</description>
      <category>react</category>
      <category>imperativeprogramming</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Dangerous world of innerHTML</title>
      <dc:creator>Kristina Hodges (Voroteliak)</dc:creator>
      <pubDate>Fri, 05 Aug 2022 21:27:00 +0000</pubDate>
      <link>https://forem.com/chrispavla/dangerous-world-of-innerhtml-1p3i</link>
      <guid>https://forem.com/chrispavla/dangerous-world-of-innerhtml-1p3i</guid>
      <description>&lt;p&gt;The innerHTML property is a part of the Document Object Model (DOM) that is used to set or return the HTML content of an element. Where the return value represents the text content of the HTML element. It allows JavaScript code to manipulate a website being displayed. More specifically, it sets or returns the HTML content (the inner HTML) of an element. &lt;/p&gt;

&lt;p&gt;For beginners, innerHTML seems like the easiest and most elegant way to manipulate basic elements on the DOM. However, as your JS becomes more involved and your DOM increases in size, innerHTML will hurt performance and introduce &lt;em&gt;security risks&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;innerHTML&lt;/strong&gt; is the source of a &lt;strong&gt;security risk&lt;/strong&gt;: it can allow malicious actors to run JavaScript directly on your website. This can enable access to your backend server and any sensitive information stored there, such as user data and passwords. &lt;br&gt;
In another scenario, a malicious script can be placed on your website and run every time a user accesses it, exposing your users directly to a security risk.&lt;/p&gt;

&lt;p&gt;The vulnerability occurs when there is an opportunity for user input. For example, consider the following live code example:&lt;/p&gt;

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

&lt;p&gt;The content of the input text field is printed beneath it when the user clicks submit. There are many use cases for this: chat apps, social media and profile editing.&lt;/p&gt;

&lt;p&gt;Now, instead, of entering an innocent ‘about me’ text, enter the following: &lt;code&gt;&amp;lt;img src="https://unsplash.it/200/200" onload="alert('User-run JavaScript!');" /&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And just like that, JavaScript is being run from the host website. In this case, we only create an alert. But the point here is what could be run. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ygx3yRJ4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hbugcd5cadse1bq4in00.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ygx3yRJ4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hbugcd5cadse1bq4in00.gif" alt="Image description" width="220" height="124"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;ACCESS TO THE BACKEND SERVER&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
A fetch request could be made to the backend server that would not be rejected as foreign because it is being made from the host website. This provides a gateway for access to everything stored on your server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;MALICIOUS SCRIPT TARGETING THE END-USER&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
The opportunity for user-input could be use to place a script on the page that will run every time the page is accessed in the future. This script could scrape user information from the browser, including sensitive user information such as usernames and passwords.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Possible alternative
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
Methods such as .createElement(), appendChild(), append(), and removeChild() allow for safe DOM manipulation without the unintended consequences of innerHTML (and innerHTML+=, more specifically). Unless you’re simply setting the text inside of an HTML tag, such as a &lt;p&gt; or &lt;/p&gt;, stay away from innerHTML.


&lt;p&gt;It is recommended that instead of innerHTML you use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Element.SetHTML() to sanitize the text before it is inserted into the DOM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Node.textContent when inserting plain text, as this inserts it as raw text rather than parsing it as HTML.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Use .textContent or .innerText where possible&lt;/em&gt;
When rendering text only to the DOM it is not necessary to use .innerHTML. Instead, can use other methods available to us to write content to the DOM: .textContent and .innerText. When using these, if HTML is included in the input, it will not be rendered as such, but as text only.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;_Conclusion: _&lt;/strong&gt;&lt;br&gt;
There are plenty of use cases where it is perfectly safe to use .innerHTML to render content to the DOM. For example, .innerHTML is very useful and safe when rendering static content (and dynamic content you are completely in control of) to the DOM.&lt;/p&gt;

&lt;p&gt;However, the security risks associated with .innerHTML occur when this is used when working with user input. In these cases: use .textContent or .innerText over .innerHTML when they can achieve the same outcome; if .innerHTML is necessary , employ a HTML sanitizer so purify user input.&lt;/p&gt;


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

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>html</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
