<?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: Kiana</title>
    <description>The latest articles on DEV Community by Kiana (@kianajade42).</description>
    <link>https://dev.to/kianajade42</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%2F650718%2F84e94704-9704-4fe3-beac-ad534e29ec88.jpeg</url>
      <title>DEV Community: Kiana</title>
      <link>https://dev.to/kianajade42</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kianajade42"/>
    <language>en</language>
    <item>
      <title>Javascript and Rails API!</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Thu, 06 Oct 2022 18:05:03 +0000</pubDate>
      <link>https://dev.to/kianajade42/javascript-and-rails-api-223m</link>
      <guid>https://dev.to/kianajade42/javascript-and-rails-api-223m</guid>
      <description>&lt;p&gt;For my fourth project with Flatiron I was tasked with building&lt;br&gt;
a Single Page Application. A javascript/CSS/HTML frontend that will communicate with a backend API built with Ruby and Rails.&lt;/p&gt;

&lt;p&gt;I work as a Nanny and the kids favorite game is a memory matching card game! we spend our time drawing small matching pictures, cutting them into card sizes, flipping them picture side down and timing each other with how fast we can flip them all over. &lt;br&gt;
I knew pretty quickly creating a memory match game for my project would be a good way to meet all my requirements and challenge myself with building a game.  &lt;/p&gt;

&lt;p&gt;I brainstormed the backend would house all my stored data for a user and their score through a gameplay. I assumed I would just display the top 3 scores but I also liked the idea of displaying users and their best score(I don't want to be the reason for a 5 and 6 year old fighting because their name keeps getting bumped off the board...)&lt;/p&gt;

&lt;p&gt;While the front end Javascript would encapsulate related data and behavior, HTML/CSS would be used to created the cards and buttons. &lt;br&gt;
I have really enjoyed learning all the ways to use CSS and wanted to challenge my knowledge and skills and implement some CSS animation on the cards which I knew I would be creating with stacking DIVs. I have been so impressed with all the hover, flip and unique features css can bring to a project.&lt;/p&gt;

&lt;p&gt;I started this project with setting up 2 repos on git hub.&lt;br&gt;
One for my frontend and one for my backend. &lt;/p&gt;

&lt;p&gt;I went through all the usual steps of creating a rails app.&lt;br&gt;
Backend (Ruby on Rails):&lt;/p&gt;

&lt;p&gt;-Create models and relationships&lt;br&gt;
-Create the database tables and seed&lt;br&gt;
-Create controllers &lt;br&gt;
-Run Rails s for starting the server&lt;/p&gt;

&lt;p&gt;Frontend (JavaScript):&lt;/p&gt;

&lt;p&gt;-setting up index.html&lt;br&gt;
-index.js &lt;br&gt;
-css file.&lt;/p&gt;

&lt;p&gt;I created the basic layout of the cards which were stacked divs that I applied photos to each and would apply a front and back class I could use in css(and later in my index.js) to orient the cards how I wanted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.html


&amp;lt;div class="board"&amp;gt;

            &amp;lt;div class="card"&amp;gt;
                &amp;lt;div class=" front facing"&amp;gt; 
                    &amp;lt;img class="face" src="css/images/apple.png"&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div class="back facing"&amp;gt;
                     &amp;lt;img class="brain" src="css/images/brain.png"&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I repeated this for each card making sure each photo had two for a match.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;css (only relevant code shown)


.board {
  display: grid;
  grid-template-columns: repeat(4, auto);
  grid-gap: 10px;
  margin: 5px;
  perspective: 500px;
}

.card {
  position: relative;
  width: 120px;
  height: 125px;

}
.facing {
  position: absolute;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  backface-visibility: hidden;
  border-radius: 12px;
  border-width: 1px;
  transition: transform 500ms ease-in-out;
}

.card.visible .back {
  transform: rotateY(-180deg);
}

.card.visible .front {
  transform: rotateY(0);
}
.back {
  position: absolute;
  height: 100%;
  width: 100%;
}
.brain {
  align-self: flex-start;
  transform: translateY(-10px);
  transition: transform 100ms ease-in-out;
  display: center;
  position: absolute;
  width: 108px;
  height: 108px;
  overflow: hidden;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my index.js I added an event listener to be able to flip a card when clicked!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cards = Array.from(document.getElementsByClassName("card"));

let game = new Match(150, cards);

   cards.forEach(card =&amp;gt; {
        card.addEventListener('click',() =&amp;gt; {
            game.flipCard(card);
        });
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I created a Match class to start with some of the basic logic for flipping cards based on if they were a match. I used the class name of "face" to compare if they were a matching photo and then by removing the visible classList to show the front of the card rather than the back if they were. This all together made it seem as though the card was being flipped!&lt;br&gt;
I loved the challenge of using css and javascript together in this as one smooth event for a user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Match {
constructor(cards){
        this.cardsArray = cards;
}

...
      getCard(card) {
        return card.getElementsByClassName('face')[0].src;
    }

   flipCard(card) {
        if(this.canFlipCard(card)){
            card.classList.add('visible');
            if(this.cardToCheck)
            this.checkForCardMatch(card);
            else
            this.cardToCheck = card;  
        }
    }

      checkForCardMatch(card) {
        if(this.getCard(card) === this.getCard(this.cardToCheck))
            this.cardMatch(card, this.cardToCheck);
        else 
            this.cardMisMatch(card, this.cardToCheck);

        this.cardToCheck = null;
    }
     cardMatch(card1, card2) {
        this.matchedCards.push(card1);
        this.matchedCards.push(card2);
        if(this.matchedCards.length === this.cardsArray.length)
            this.win(); 
    }
       cardMisMatch(card1, card2) {
        this.busy = true;
        setTimeout(() =&amp;gt; {
            card1.classList.remove('visible');
            card2.classList.remove('visible');
            this.busy = false;
        }, 1000);
    }

}

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

&lt;/div&gt;



&lt;p&gt;To make all of this make sense I needed to check if a card was &lt;br&gt;
 even able to be flipped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  canFlipCard(card){
     return !this.busy &amp;amp;&amp;amp; !this.matchedCards.includes(card) &amp;amp;&amp;amp; card !== this.cardToCheck
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These 3 conditions are what needed to be meet in order to allow a card to be flipped(clicked).&lt;/p&gt;

&lt;p&gt;If a card was not busy(ex. a click event... a user already clicked that card)&lt;br&gt;
if the card clicked is not already a matched card &lt;br&gt;
and if the card is not the current card being checked.&lt;/p&gt;

&lt;p&gt;The return of all these conditions would be a boolean value of true or false... If all 3 of those conditions are false the value of canFlipCard would return true and the card would be able to be clicked and therefore flipped!&lt;/p&gt;

&lt;p&gt;In the startGame function is where the card to check starts as null because nothing has been clicked yet and also set matchedCards to an empty array so they could be easily compared and stored for the scoring logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;startGame(){
        this.cardToCheck = null;
        this.matchedCards = []
        this.hideCards();
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From there I created the scoring logic for the flip count,&lt;br&gt;
and timer counting down.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.js


constructor(totalTime, cards){
        this.cardsArray = cards;
        this.totalTime = totalTime;
        this.timeRemaining = totalTime;
        this.timer = document.getElementById('timer');
        this.ticker = document.getElementById('flips');
    }
 startGame()
        this.cardToCheck = null;
        this.totalClicks = 0;
        this.timeRemaining = this.totalTime;
        this.matchedCards = [];
        this.busy = true;
        setTimeout(() =&amp;gt; {
            this.countDown = this.startCountDown();
            this.busy = false;
        }, 500);
        this.hideCards();
        this.timer.innerText = this.timeRemaining;
        this.ticker.innerText = this.totalClicks;
    }
   hideCards(){
         this.cardsArray.forEach(card =&amp;gt; {
             card.classList.remove('visible');
         });
     }
     startCountDown(){

         return setInterval(() =&amp;gt; {
             this.timeRemaining--;
             this.timer.innerText = this.timeRemaining;
             if
             (this.timeRemaining === 0)
             this.gameOver();
         }, 1000);

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.html

&amp;lt;div class="info"&amp;gt;
            Timer: &amp;lt;span id="timer"&amp;gt;150&amp;lt;/span&amp;gt;
 &amp;lt;/div&amp;gt;
        &amp;lt;div class="info"&amp;gt;
            Flips: &amp;lt;span id="flips"&amp;gt;0&amp;lt;/span&amp;gt;
        &amp;lt;/div
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From here, in the API I created some data to fetch and display a user and their scores. In order to get all of this is display properly in the frontend I had to add the render json line so the data could be readable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class UsersController &amp;lt; ApplicationController
def index
    @users = User.all
    render json: @users
end


class GamesController &amp;lt; ApplicationController
def index
    @games = Game.all
    render json: @games
end
end

seed.rb
User.create(username: "KJL")
User.create(username: "Kiana")
User.create(username: "K2")

Game.create(user_id: 1, score: 23, time: 67)
Game.create(user_id: 2, score: 14, time: 45)
Game.create(user_id: 3, score: 19, time: 84)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and in the frontend,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;api.js

   function callUsers(){
    return fetch('http://127.0.0.1:3000/users')
    .then(res =&amp;gt; res.json())
    .then(json =&amp;gt; renderUsers(json))
}

  function  callGames() {
  return fetch('http://127.0.0.1:3000/games')
    .then(resp =&amp;gt; resp.json())
    .then(json =&amp;gt; renderGames(json))

}
function renderUsers(users){
 const usersshow = document.getElementById("user-display")
  users.forEach(user =&amp;gt; {
    const h2 = document.createElement('h2')
    h2.innerHTML = user.username
    usersshow.appendChild(h2)
  })
}

index.html

 &amp;lt;h1 class="info"&amp;gt;Highscores&amp;lt;/h1&amp;gt;
            &amp;lt;div id="user-display"&amp;gt; &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I later decided to add a "login to play" form. &lt;br&gt;
This would have a user create a username, once they submit it, the game would start. The score would be stored in localstorage and if a user completes the game without time running out they it would be persisted to the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.html

   &amp;lt;h2 class="rules"&amp;gt;Submit a username to play!&amp;lt;/h2&amp;gt;
            &amp;lt;div class="layout" id="login-form"&amp;gt;
                &amp;lt;form autocomplete="off" id="username" class="layout" action="http://127.0.0.1:3000/users" method="post"&amp;gt;
                    &amp;lt;input class="rules" id="login-field" type="text" name="username" value="" placeholder="username"&amp;gt;
                    &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
                    &amp;lt;input class="startOver" type="submit" value="Lets Play!"&amp;gt;
                    &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
                &amp;lt;/form&amp;gt;

            &amp;lt;/div&amp;gt;

index.js
let loginForm = (document.getElementById("login-form"))

loginForm.addEventListener('submit',e =&amp;gt; {
        e.preventDefault()
      let user = player.value
      let body = {username: user}
         createUser(body)
          if(!body.null)
           { overlays.forEach(overlay =&amp;gt;
       overlay.classList.remove('visible'));
       game.startGame()}
       else {
        alert("please enter a username")
       }
        }
        )


api.js
 function createUser(username){
        return fetch('http://127.0.0.1:3000/users',{
        method: 'POST',
        headers: {
         "Content-Type": "application/json",
         "Accept": "application/json"
         },
        body: JSON.stringify(username)
    })
}
   function  createGame(result){
    return fetch('http://127.0.0.1:3000/games',{
        method: 'POST',
        headers: {
         "Content-Type": "application/json",
         "Accept": "application/json"},
        body: JSON.stringify(result)
    })
}

index.js

    win() {
            localStorage.setItem("score", this.totalClicks)
            localStorage.setItem("time", this.timeRemaining)
            document.getElementById('win-text').classList.add('visible')
            let flipResult = localStorage.getItem("score")     
            let timeResult = localStorage.getItem("time") 
            const result = {score: flipResult, time: timeResult}
                 createGame(result)
            document.getElementById("flip-form").innerHTML = flipResult
            document.getElementById("time-form").innerHTML = timeResult

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

&lt;/div&gt;



&lt;p&gt;And in the backend updated the controllers, routes and models&lt;br&gt;
&lt;/p&gt;

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

class UsersController &amp;lt; ApplicationController
def create 
    @user = User.find_or_create_by(username: params[:username])
end


  private

  def user_params
    params.require(:username).permit(:id)
  end
end

class GamesController &amp;lt; ApplicationController
def create
    @user = User.find_by(username: params[:username])
    Game.create(score: params[:score], time: params[:time])
  end
end

models

class User &amp;lt; ApplicationRecord
      has_many :games
end
class Game &amp;lt; ApplicationRecord
    belongs_to :user
end

routes.rb

Rails.application.routes.draw do
  resources :games, only: [:index, :create]

  resources :users, only: [:index, :show, :create]

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

&lt;/div&gt;



&lt;p&gt;I followed this same pattern to add a "leave a review" feature at the end of the game, these reviews were displayed in the game play window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.html

&amp;lt;h3 class="rules"&amp;gt; Leave a review! &amp;lt;/h3&amp;gt;
            &amp;lt;form autocomplete="off" id="comment-form" class="layout" action="index.html" method="post"&amp;gt;
                &amp;lt;input class="rules" id="user-field" type="text" name="" value="" placeholder="username"&amp;gt;
                &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
                &amp;lt;input class="rules" id="comment-field" type="text" name="" value="" placeholder="comment"&amp;gt;
                &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
                &amp;lt;input class="startOver" type="submit" value="submit"&amp;gt;
                &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
            &amp;lt;/form&amp;gt;


api.js

    function  createComment(rrr, rrrr){
    return fetch('http://127.0.0.1:3000/comments',{
        method: 'POST',
        headers: {
         "Content-Type": "application/json",
         "Accept": "application/json"},
        body: JSON.stringify(rrr, rrrr)
    })
    .then(res =&amp;gt; res.json())
}

 function renderComments(comments){
 const reviews = document.getElementById("comments")
//  const userreviews = document.getElementById("user-comments")
  comments.forEach(comment =&amp;gt; {
    const h2 = document.createElement('h2')
    const h3 = document.createElement('h3')
    h2.innerHTML = comment.comment
    h3.innerHTML = comment.username
    reviews.appendChild(h2)
    reviews.appendChild(h3)

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

&lt;/div&gt;



&lt;p&gt;In the backend I updated the routes.rb and created a new comments table  with a username and a score.&lt;br&gt;
&lt;/p&gt;

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

class CommentsController &amp;lt; ApplicationController
def index
   @comments = Comment.all
   render json: @comments
end
def create 
    @comment = Comment.create(username: params[:username], comment: params[:comment])
    render json: @comment
end
def show
    @comment = Comment.find(params[:comment])
    render json: @comment
end
end

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

&lt;/div&gt;



&lt;p&gt;To get all of these pieces working together I wrapped my index.js with a&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.js
window.addEventListener('DOMContentLoaded', e =&amp;gt; { 

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

&lt;/div&gt;



&lt;p&gt;and my index.html file with an onload function to make my fetch calls&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.html
&amp;lt;body onload="loadpage()"&amp;gt;
    &amp;lt;script&amp;gt;
        function loadpage() {
            callUsers(), callComments(), callGames()
        }
    &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with async defined in my index.html I could use all of this to leverage asynchronous functions for a smoother user game play(or impatient children)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.html
  &amp;lt;script src="src/index.js" async&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src="src/api.js" async&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One of the most important things I learned while working through this project was the attention I needed to have with spelling errors and exactly what I was passing as data.&lt;br&gt;
things like calling user_params vs. params when creating a user...&lt;em&gt;insert eyeroll&lt;/em&gt;... or calling HTTP vs HTTPS in get/post requests...&lt;em&gt;insert bigger eyeroll&lt;/em&gt;...&lt;br&gt;
Overall I really enjoyed building out this project and learning how to make many things come together with Javascript, an API and css.  &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>rails</category>
      <category>api</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Ruby on Rails, MVC architecture &amp; data modeling</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Fri, 23 Sep 2022 04:34:27 +0000</pubDate>
      <link>https://dev.to/kianajade42/ruby-on-rails-mvc-architecture-data-modeling-290c</link>
      <guid>https://dev.to/kianajade42/ruby-on-rails-mvc-architecture-data-modeling-290c</guid>
      <description>&lt;p&gt;For my 3rd project with Flatiron I was tasked with building a complete Ruby on Rails application that manages related data through complex forms and RESTful routes. &lt;br&gt;
This was a real opportunity to put together all my knowledge about Ruby on rails, MVC architecture and data modeling.&lt;br&gt;
The idea was to build a content management system. &lt;br&gt;
After some brainstorming I decided to build a Task manager app. &lt;br&gt;
This would serve as a place to start with my table associations in an easy way. A lists would belong to a user and a list would have many tasks.&lt;br&gt;
I started with a new rails app and began on the backend. &lt;br&gt;
I started with my tables for and everything I assumed a task would need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create_table "lists", force: :cascade do |t|
    t.string "name"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "task"
  end

  create_table "tasks", force: :cascade do |t|
    t.string "task"
    t.boolean "completed"
    t.date "due_date"
    t.text "details"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From there I set up my controllers and basic model associations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class List &amp;lt; ActiveRecord::Base
  has_many :tasks, dependent: :destroy
  accepts_nested_attributes_for :tasks
end

class Task &amp;lt; ActiveRecord::Base
  belongs_to :list
end

class User &amp;lt; ApplicationRecord
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Within the list model I had to specify&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"accepts_nested_attributes_for :tasks"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this would be how rails would know how to find the nested attributes for a list. &lt;/p&gt;

&lt;p&gt;I then installed the Devise gem to add user authentication. &lt;br&gt;
I have used the devise gem before and I love how straight forward the implementaion is.&lt;br&gt;
It does all the heavy lifting of setting up sign up/log in functionalities along with validations. &lt;br&gt;
I followed the rails docs to add it,&lt;br&gt;
"&lt;a href="https://guides.railsgirls.com/devise"&gt;https://guides.railsgirls.com/devise&lt;/a&gt;" &lt;/p&gt;

&lt;p&gt;Moving onto the (V)iews part of my MVC pattern I set up the corresponding folders. &lt;br&gt;
list&lt;br&gt;
-index.html.erb&lt;br&gt;
-show.html.erb&lt;br&gt;
task&lt;br&gt;
-index.html.erb&lt;br&gt;
-show.html.erb&lt;/p&gt;

&lt;p&gt;I begin with creating some dummy data in my seed.rb, This would allow me to set up functionalities on the browser and display them how I liked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 Task.create(task: "Roadtrip", details: "Rent car") 
 Task.create(task: "Wedding", details: "In mexico")
 Task.create(task: "Eye appt", details: "Mon at 11am")

List.create(name: "Trips")
List.create(name: "Appointments")

User.create(email: "kianajade42@gmail.com", password: "password")
User.create(email: "kjl@gmail.com", password: "pass")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the list/index.html.erb I set up some basic displaying of the data along with a link_to helper that would take a user to a partial form to create a list that accepted nested attributes for tasks.&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;h3 class='title'&amp;gt; Currently To Do:&amp;lt;/h3&amp;gt;
  &amp;lt;h3&amp;gt;&amp;lt;%= link_to "Add New", new_list_path  %&amp;gt;&amp;lt;/h3&amp;gt;
      &amp;lt;% @lists.each do |list| %&amp;gt;
      &amp;lt;h4 class="list-item"&amp;gt; &amp;lt;%=list.name%&amp;gt; &amp;lt;/h4&amp;gt;
      &amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Being new at routing a rails I ran rails routes in my console which provided me with the correct link to the new/create methods in my lists_controller.&lt;br&gt;
I had to specify in my routes.rb the exact route.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;routes.rb 

post '/lists/:id/tasks/new', to: 'tasks#create'

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

&lt;/div&gt;



&lt;p&gt;This is telling rails that when the specified /new route is called to look for the new/create methods in the controller and post it to the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; def new
   @user = User.find_by(@current_user)
    @list = List.new
    @list.tasks.build
   end


  def create
    @list = List.new(list_params)
    @list.task = @current_user
    if @list.save
      redirect_to @list
    else
      render :new
    end

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

&lt;/div&gt;



&lt;p&gt;The new is responsible for rendering the form and the create is what is responsible for creating/storing the data. &lt;br&gt;
 I created a partial form within my list folder.&lt;br&gt;
to display this logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
_list.html.erb

&amp;lt;%= form_for(@list) do |list_form| %&amp;gt;
   &amp;lt;%# %= list_form.hidden_field :list_id %&amp;gt;
   &amp;lt;ul&amp;gt; &amp;lt;h4&amp;gt;List Name: &amp;lt;%= list_form.text_field :name, placeholder: "Create a List" %&amp;gt;&amp;lt;/h4&amp;gt;
     &amp;lt;%= list_form.fields_for :tasks, @list.tasks do |task_field| %&amp;gt;
        &amp;lt;h4&amp;gt; Task: &amp;lt;%= task_field.text_field :task, placeholder: "Create a Task" %&amp;gt;&amp;lt;/h4&amp;gt;
        &amp;lt;h4&amp;gt; Details: &amp;lt;%= task_field.text_field :details, placeholder: "Details" %&amp;gt;&amp;lt;/h4&amp;gt; 
        &amp;lt;h4&amp;gt; Confirm user id: &amp;lt;%= task_field.text_field :user_id, placeholder: @user.email %&amp;gt; 
      &amp;lt;% end %&amp;gt;

      &amp;lt;h4&amp;gt;&amp;lt;%= list_form.submit %&amp;gt;&amp;lt;/h4&amp;gt;
    &amp;lt;% end %&amp;gt;
  &amp;lt;/ul&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From there I created the edit/adding a new single task to a list with the same pattern.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;routes.rb 
get 'tasks/:id/edit', to: 'tasks#edit', as: :edit_task
patch 'tasks/:id', to: 'tasks#update'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the 'as: edit_task' appended to the route is a helper to create custom route to be called on in a link_to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lists_controller.rb

def edit
        @list = List.find_by(id: params[:id])

    end

    def update
        @list = List.find(params[:id])
        @list.update(list_params)
        redirect_to list_path(@list)
    end

tasks_controller.rb

 def edit
    @task = Task.find(params[:id])
  end

def update 
    @task = Task.find(params[:id])
    @task.update(task_params)
    redirect_to list_tasks_path(@task)
end

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

&lt;/div&gt;



&lt;p&gt;within the views I used link_to helpers again.&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;h4&amp;gt;&amp;lt;%= link_to "edit", edit_task_path %&amp;gt;&amp;lt;/h4&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To practice a DRY code, because my new/edit forms were working with the same fields I called upon the form in both folders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lists/new.html.erb

&amp;lt;h4&amp;gt;&amp;lt;%= link_to "view all lists", lists_path %&amp;gt;&amp;lt;/h4&amp;gt;
&amp;lt;ul&amp;gt;&amp;lt;h2&amp;gt;Create New&amp;lt;/h2&amp;gt;

&amp;lt;%= render 'list' %&amp;gt;

lists/edit.html.erb

&amp;lt;h2&amp;gt;Editing:&amp;lt;/h2&amp;gt;
&amp;lt;h3&amp;gt;&amp;lt;%= @list.name %&amp;gt;&amp;lt;/h3&amp;gt;
 &amp;lt;%= render 'list' %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another requirement of this project was to creating validations on my form, this was an easy add.&lt;br&gt;
 Within the controllers/models I specified what needed to be in the params and what to validate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list.rb
 validates_presence_of :name, uniqueness: true

task.rb
validates_presence_of :task, :details, presence: true

list_controller.rb
def list_params
    params.require(:list).permit(:name, :task, tasks_attributes: [:task, :completed, :due_date, :details])
  end

tasks_controller.rb
def task_params
     params.require(:task).permit(:task, :completed, :due_date, :details)
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From there I created an _errors file that could be used within the form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lists/_errors.html.erb

&amp;lt;% if @list.errors.any? %&amp;gt;
    &amp;lt;div&amp;gt;
    &amp;lt;h2&amp;gt;
        &amp;lt;%= pluralize(@list.errors.count, "error") %&amp;gt;
        prohibited this from being saved:
    &amp;lt;/h2&amp;gt;

    &amp;lt;ul&amp;gt;
        &amp;lt;% @list.errors.full_messages.each do |msg| %&amp;gt;
         &amp;lt;li&amp;gt;&amp;lt;%= msg %&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;% end %&amp;gt;
    &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and placed&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;%= render 'errors' %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;at the top of my _list.html.erb form. &lt;/p&gt;

&lt;p&gt;This would render an error message if a user tried to create a list without a name. &lt;br&gt;
I followed this pattern again within the tasks folder and replaced the necessary instance variables.&lt;/p&gt;

&lt;p&gt;I had an idea that I wanted a user to be able to see the most recently created tasks with a little quick view feature on the homepage. This was mostly done with CSS and I enjoyed figuring out how to use it to my advantage to create a unique feature.&lt;br&gt;
At the end of the day it was a pretty basic stacking of div's that I displayed different data on using a scope method within my task model.&lt;br&gt;
I set a hidden hover effect on the top div which would would then show the recently created tasks. &lt;br&gt;
I felt this feature really made it possible to show the MVC pattern in a simple way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Task &amp;lt; ActiveRecord::Base

scope :most_recent, -&amp;gt; {order(created_at: :desc).limit(2)}

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

&lt;/div&gt;



&lt;p&gt;This was a most_recent method that can be used in the controller telling it to show the tasks displayed by the most recent in descending order(last two created) but only the last 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lists_controller.rb

  def index
    @list = Task.most_recent
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lists/index.html.erb

&amp;lt;div class=out&amp;gt;
&amp;lt;h2&amp;gt; Recently added &amp;lt;/h2&amp;gt;
&amp;lt;ul&amp;gt;
&amp;lt;div class=quick&amp;gt;

 &amp;lt;% @list.each do |l| %&amp;gt;
 &amp;lt;div class= "list-item"&amp;gt;
    &amp;lt;h4&amp;gt; &amp;lt;%= l.task %&amp;gt; &amp;lt;/h4&amp;gt;
         &amp;lt;/div&amp;gt;
      &amp;lt;% end %&amp;gt; 

       &amp;lt;/div&amp;gt;
      &amp;lt;/ul&amp;gt;

&amp;lt;div class="innerquick"&amp;gt;
&amp;lt;h3&amp;gt; Quick view &amp;lt;/h3&amp;gt;
      &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For sake of space only the relevant css is below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;application.sccs

.out {
  position: relative;
  margin-top: 2px;
  margin-right: 150px;
  margin-left: 150px;
  padding: 15px;
  height: 300px;
}

.quick {

  display: grid;
  grid-template: 1fr / 1fr;
  font-size: 1.5em;
  padding: 5px;
  text-align: center;
  position: absolute;
  width: fit-content;
  block-size: fit-content;
  margin-left: 20px;
  line-height: 200px;
}

.innerquick {
  display: grid;
  font-size: 1.5em;
  padding: 75px;
  text-align: center;
  position: absolute;
  width: fit-content;
  block-size: fit-content;
  line-height: 500px;
}
.innerquick:hover {
  opacity: 0;
  transition-delay: 0.3s;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a final requirement I has to create a join table for a has_many through association which includes a user submittable attribute other than its foreign keys. &lt;br&gt;
I thought of expanding the app past a single user creating their own list and tasks and make it so an admin could assign certain tasks to a user and the could see what tasks were theirs to complete. I updated my model associations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class List &amp;lt; ActiveRecord::Base
  has_many :tasks, dependent: :destroy
  has_many :users, through: :tasks
end

class Task &amp;lt; ActiveRecord::Base
belongs_to :list
belongs_to :user 
end

class User &amp;lt; ApplicationRecord
  has_many :tasks
  has_many :lists, through: :tasks
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and adding a new users folder along with index and show pages so i could display all the users and their associated tasks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;users/index.html.erb
&amp;lt;h1&amp;gt; All Users: &amp;lt;/h1&amp;gt;
  &amp;lt;div&amp;gt;
    &amp;lt;ul class="tasks-list"&amp;gt;
      &amp;lt;% @user.each do |t| %&amp;gt;
          &amp;lt;li class="list-item"&amp;gt;
          &amp;lt;h3&amp;gt;&amp;lt;%= link_to t.email, show_path(t)%&amp;gt;&amp;lt;/h3&amp;gt; 
          &amp;lt;/li&amp;gt;
          &amp;lt;%end%&amp;gt;
    &amp;lt;/ul&amp;gt;
  &amp;lt;/div&amp;gt;

users/show.html.erb
 &amp;lt;h2&amp;gt; All tasks for &amp;lt;/h2&amp;gt;
 &amp;lt;h1&amp;gt;&amp;lt;%= @user.email%&amp;gt;: &amp;lt;/h1&amp;gt;

&amp;lt;div&amp;gt;
  &amp;lt;div&amp;gt;
    &amp;lt;ul class="tasks-list"&amp;gt;
    &amp;lt;div class="list-item"&amp;gt;
    &amp;lt;% if !@user.tasks.nil? %&amp;gt;
      &amp;lt;% @user.tasks.each do |t| %&amp;gt;
          &amp;lt;h3&amp;gt;&amp;lt;%=t.task %&amp;gt;&amp;lt;/h3&amp;gt;
          &amp;lt;h4&amp;gt;&amp;lt;%= t.details %&amp;gt;&amp;lt;/h4&amp;gt;
          &amp;lt;%end%&amp;gt;
       &amp;lt;%else%&amp;gt;
            &amp;lt;h3&amp;gt; This user has no tasks to complete&amp;lt;/h3&amp;gt;
         &amp;lt;%end%&amp;gt;
       &amp;lt;/div&amp;gt; 
    &amp;lt;/ul&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;setting up the has_many through: allowed me to chain logic onto instances of the User model that now would respond to a 'tasks' method.&lt;/p&gt;

&lt;p&gt;I also was able to use this within my tasks index and show page to display the same association.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tasks/show.html.erb

&amp;lt;h3  class="tasks-header"&amp;gt; &amp;lt;%= @task.task %&amp;gt;&amp;lt;/h3&amp;gt;
 &amp;lt;div class="tasks-item"&amp;gt; 
 &amp;lt;div&amp;gt;
&amp;lt;h4&amp;gt;Details:&amp;lt;/h4&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;%= @task.details %&amp;gt;&amp;lt;/p&amp;gt; 

&amp;lt;/div&amp;gt;

&amp;lt;/div&amp;gt;
 &amp;lt;h5&amp;gt;this task belongs to: 
     &amp;lt;%=@task.user.email %&amp;gt; &amp;lt;/h5&amp;gt;
&amp;lt;%= button_to "Delete", tasks_path(@task), :method =&amp;gt; :delete %&amp;gt;

tasks/index.html.erb

 &amp;lt;ul class="tasks-list"&amp;gt;
      &amp;lt;% @tasks.each do |t| %&amp;gt;
          &amp;lt;li class="list-item"&amp;gt;
          &amp;lt;h3&amp;gt;&amp;lt;%=t.task %&amp;gt;&amp;lt;/h3&amp;gt;
            &amp;lt;div&amp;gt;
             &amp;lt;h4&amp;gt;&amp;lt;%= t.details %&amp;gt;&amp;lt;/h4&amp;gt;

            &amp;lt;/div&amp;gt;
            &amp;lt;h5&amp;gt;belongs to &amp;lt;%=t.user.email%&amp;gt; &amp;lt;/h5&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;%end%&amp;gt;
    &amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my index page I had to remember I was mapping over the data and therefore had to append t.user.email instead of defining the instance of task itself.&lt;/p&gt;

&lt;p&gt;I had plenty of other features in this project that generally fit the same pattern. Thats what I find so great about Ruby on Rails, MVC architecture &amp;amp; data modeling, it provides an opportunity for repetition. There is no better way than building out a project and the executing all details that allow these concepts to fully be grasped. &lt;/p&gt;

&lt;p&gt;On to the next project!&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Sinatra&amp;Active Record</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Sat, 12 Feb 2022 22:56:08 +0000</pubDate>
      <link>https://dev.to/kianajade42/sinatraactive-record-42k2</link>
      <guid>https://dev.to/kianajade42/sinatraactive-record-42k2</guid>
      <description>&lt;p&gt;For my 2nd project at Flatiron school I had to create an app using Sinatra and active record. I started with mapping out the project I wanted to create, one of the main requirements for this project was to set up an authentication for a user using the Bcrypt gem. That was a place to start! I needed to create the ability for a user to login &amp;amp; sign up. &lt;/p&gt;

&lt;p&gt;After having an idea of creating a tattoo artist online portfolio for this project, I created my project folder and sub-folders.&lt;br&gt;
I ran bundle init in the command line which created a Gemfile where i added the gems I would need for this project.&lt;br&gt;
Gemfile&lt;/p&gt;

&lt;p&gt;`source '&lt;a href="http://rubygems.org"&gt;http://rubygems.org&lt;/a&gt;'&lt;br&gt;
gem 'sinatra'&lt;br&gt;
gem 'activerecord', '~&amp;gt; 6.0.1', :require =&amp;gt; 'active_record'&lt;br&gt;
gem 'sinatra-activerecord', :require =&amp;gt; 'sinatra/activerecord'&lt;br&gt;
gem 'rake'&lt;br&gt;
gem 'require_all'&lt;br&gt;
gem 'sqlite3'&lt;br&gt;
gem 'thin'&lt;br&gt;
gem 'shotgun'&lt;br&gt;
gem 'pry'&lt;br&gt;
gem "tux"&lt;br&gt;
gem "bcrypt", "~&amp;gt; 3.1"&lt;/p&gt;

&lt;p&gt;group :test do&lt;/p&gt;

&lt;p&gt;gem 'rspec'&lt;br&gt;
  gem 'capybara'&lt;br&gt;
  gem 'rack-test'&lt;br&gt;
  gem 'database_cleaner'&lt;br&gt;
end`&lt;/p&gt;

&lt;p&gt;I then needed to create the config folder and environment file.&lt;br&gt;
This is a very important file; it's where your database connection is made and will connect your app folder with the rest of the files that require it.&lt;br&gt;
When I initially set this up I had an error of my database/environment not being configured. I spent some time searching for answers which lead  me to learn that I had to set and specify my database.&lt;/p&gt;

&lt;p&gt;`ENV['SINATRA_ENV'] ||= "development"&lt;/p&gt;

&lt;p&gt;require 'bundler/setup'&lt;br&gt;
require 'capybara/dsl'&lt;br&gt;
Bundler.require(:default, ENV['SINATRA_ENV'])&lt;/p&gt;

&lt;p&gt;set :database, {adapter: "sqlite3", database: "development.db"} &lt;br&gt;
require_all 'app'`&lt;/p&gt;

&lt;p&gt;In the config.ru is where I loaded the environment and mounted the application controller. As my app grew I would include the other controllers here as well.&lt;/p&gt;

&lt;p&gt;config.ru&lt;/p&gt;

&lt;p&gt;&lt;code&gt;require_relative './config/environment'&lt;br&gt;
if ActiveRecord::Migrator.needs_migration?&lt;br&gt;
raise 'Migrations are pending. Run&lt;/code&gt;rake db:migrate&lt;code&gt;to resolve the issue.'&lt;br&gt;
end&lt;br&gt;
use Rack::MethodOverride&lt;br&gt;
run ApplicationController&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In app/controllers folder I created an application_controller.rb file&lt;/p&gt;

&lt;p&gt;`class ApplicationController &amp;lt; Sinatra::Base&lt;br&gt;
configure do&lt;br&gt;
set :public_folder, 'public'&lt;br&gt;
set :views, 'app/views' enable :sessions&lt;br&gt;
set :session_secret, 'password_security'&lt;br&gt;
end&lt;/p&gt;

&lt;p&gt;get '/' do&lt;br&gt;
'Hello, World!'&lt;br&gt;
end`&lt;/p&gt;

&lt;p&gt;from here I could run shotgun and the browser at the local host address was up and running!&lt;/p&gt;

&lt;p&gt;Since I needed to use activerecord, I set up my Rakefile.&lt;br&gt;
this specified tasks and actions I would need, I loaded the environment and required 'sinatra/activerecord/rake'. &lt;br&gt;
Rakefile&lt;br&gt;
&lt;code&gt;require_relative './config/environment'&lt;br&gt;
require 'sinatra/activerecord/rake'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;From there I added my Models for the corresponding database table, it will inherit from the ActiveRecord::Base class, which means that it has access to a number of methods for working with the database.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;class User &amp;lt; ActiveRecord::Base&lt;br&gt;
has_secure_password &lt;br&gt;
has_many :tattoos&lt;br&gt;
end&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;has_secure_password is specified so i could set up authentication with Bcrypt. &lt;/p&gt;

&lt;p&gt;I then create a Database folder (db) and ran migrations to create a users tables.&lt;/p&gt;

&lt;p&gt;I had to type &lt;code&gt;rake db:create_migration NAME=create_users&lt;/code&gt;, to create the table and populate it with my columns, then run rake db:migrate for all of this to create a schema file.Then rake:create to create the database for my app.&lt;/p&gt;

&lt;p&gt;user table&lt;/p&gt;

&lt;p&gt;&lt;code&gt;class CreateUsers &amp;lt; ActiveRecord::Migration[6.0]&lt;br&gt;
  def change&lt;br&gt;
    create_table :users do |t|&lt;br&gt;
      t.string :username&lt;br&gt;
      t.string :password_digest&lt;br&gt;
      t.timestamps null: false&lt;br&gt;
    end&lt;br&gt;
  end&lt;br&gt;
end&lt;/code&gt;&lt;br&gt;
  From here I had to also create a tattoos table and controller and model. This was wall generally set up the same way as the user.&lt;br&gt;
 I then moved onto my views and started with the users to create a sign up/login page which I would then in my users_controller use to correlate to the appropriate CRUD action. &lt;br&gt;
users_controller.rb&lt;br&gt;
`class UsersController &amp;lt; ApplicationController&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get "/signup" do
    erb :"users/new"
end 

post "/signup" do
    user = User.new(params[:user])
    if user.save
        session[:user_id] = user.id 
        redirect "/users/#{user.id}"
    else 
        @errors = user.errors.full_messages.join(" - ")
        erb :'/users/new'
    end
end

get "/login" do
    erb :"users/login"
end 

post "/login" do
    user = User.find_by(username: params[:user][:username])
    if user &amp;amp;&amp;amp; user.authenticate(params[:user][:password])
        session[:user_id] = user.id 
        redirect "/users/#{user.id}"
    else 
        redirect "/login"
    end
end

get "/users/:id" do
    @user = User.find_by(id: params[:id])
    erb :"/users/show"
end 

get "/logout" do
    session.clear
    redirect '/'
end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;end ` &lt;/p&gt;

&lt;p&gt;After all of this logic was set up I again followed the same process for setting up the tattoos MVC.&lt;br&gt;&lt;br&gt;
The set up of this project was perhaps the most challenging and yet most simple! Its rather straight forward but it takes working out set by step in each folder to fully understand what you need to specify for the database and how it all works together. This project was certainly a great stepping stone in my knowledge as  developer.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>First react app creation.</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Thu, 16 Sep 2021 21:43:57 +0000</pubDate>
      <link>https://dev.to/kianajade42/first-react-app-creation-4g1o</link>
      <guid>https://dev.to/kianajade42/first-react-app-creation-4g1o</guid>
      <description>&lt;p&gt;When I started brainstorming what to build for my first React project I wanted something that would keep me motivated through the errors I knew I would run into. I decided on a simple quiz app themed after The Office since it's my favorite show.&lt;br&gt;
This quiz would display quotes that a user has to select who they believe said it, At the end the user is redirected to a page that displays their score. I felt this would keep me motivated and excited because it's a quiz I wanted to be able to take myself!&lt;/p&gt;

&lt;p&gt;The main building requirements I had to meet were,&lt;br&gt;
1.Fetching Rails API backend to persist data.&lt;br&gt;
2.using Redux and redux-thunk middleware to modify state.&lt;br&gt;
3.Using React-router.&lt;/p&gt;

&lt;p&gt;I started building this project by creating my backend. I followed a walk through of creating a rails API where the data would be pulled from.  I wrote out all the data myself rather than finding an open-source API to build a front end to pair with because I was building a very specific project that needed direct quotes and specific characters as answers. &lt;br&gt;
This was certainly the most tedious part and of course as a developer I don't want to be responsible for creating and hardcoding all my data but I felt for the project I was doing I wanted to really focus on creating what I wanted and not relaying on finding an open-source api to fit. Maybe later down the road when I have a firmer understanding Id love to challenge myself to extract nested data or manipulate data to fit my ideas. &lt;/p&gt;

&lt;p&gt;From there I started building the frontend with 'create-react-app', another walk through that made the set up of this project very easy.  I started with mapping out the lifecycle of the components and where/how they would be displayed and updated.&lt;br&gt;
At the top layer, in my App component React router made a painless set up of wrapping my components so they could be easily navigated to. React-Router allows changing the browser URL  while staying in sync with the UI as the user(or developer) navigates. React router really made debugging and setting up each page a breeze.&lt;br&gt;
 Since it uses component structure to call components, I could display the appropriate information without the page refreshing while I was in the middle of working on a component.&lt;/p&gt;

&lt;p&gt;Home would be a presentational component to introduce the user to the quiz and the option to link a user to other pages in the app. &lt;br&gt;
The Quiz component would be a container component that would have all the logic for the app along with rendering JSX.&lt;br&gt;
The Result page would simply update the state of 'score' and display it while also posting to the API. Finally, Highscores would be a leaderboard to compare different users scores.&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
return (
  &amp;lt;div className="App"&amp;gt;
     &amp;lt;Router&amp;gt;
      &amp;lt;Switch &amp;gt;
        &amp;lt;Route exact path="/"&amp;gt;
          &amp;lt;Home /&amp;gt;
        &amp;lt;/Route&amp;gt;
         &amp;lt;Route exact path="/quiz"&amp;gt; 
             &amp;lt;quiz/&amp;gt;
        &amp;lt;/Route&amp;gt;
        &amp;lt;Route exact path="/results"&amp;gt;
          &amp;lt;Results /&amp;gt;
        &amp;lt;/Route&amp;gt;
         &amp;lt;Route exact path="/highscore"&amp;gt;
          &amp;lt;Highscore/&amp;gt;
        &amp;lt;/Route&amp;gt;
      &amp;lt;/Switch&amp;gt;
      &amp;lt;/Router&amp;gt;
    &amp;lt;/div&amp;gt; 
  );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I had to create a store using thunk-middleware. I created a separate store folder with action, reducer and selector files. &lt;br&gt;
The action folder is where I fetched data from my backend, the reducer provided access to that data for the store and in my selector file I used the react hook of useState which allowed me to extract data from the Redux store state and pass it to my Quiz component.&lt;/p&gt;

&lt;p&gt;Setting up my action to fetch the API data certainly took a bit of preplanning for how I wanted to work with the data. I decided on a promise.all because I needed two sources of data from my API, getting the questions as well as the highscores that were stored. I could have also separated out fetching these but seeing as promise.all returns an array I could easily map over the data, render it to json, store it in state in my reducer to be passed through a selector and call on the index throughout my app, Keeping it DRY.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;action.js

export function fetchQuestions(){
  console.log("c")
  return function(dispatch){
  Promise.all([
    fetch("http://127.0.0.1:3000/questions"),
    fetch("http://127.0.0.1:3000/scores",
  { method:"GET",
headers:{ "Content-Type":"application/json",
          "Accept":"application/json"
}
})
]).then(function (responses) {
    return Promise.all(responses.map(function (response) {
    return response.json();
    }));
}).then(data =&amp;gt; {
   dispatch({ type: fetchSuccess, payload: data })
    console.log(data);
}).catch(function (error) {
    console.log(error);
})}};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because this was the first time I worked with a promise.all I had some console.logs just to follow what was being executed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;reducer.js

const quizReducer = (state = {}, action) =&amp;gt; {
    switch (action.type){
        case fetchRequest:
             return state
        case fetchSuccess:
        return {...state, data:action.payload}
        default:
        return state    
    }    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;selector.js
import { useSelector } from "react-redux";
export const getData = (state) =&amp;gt; {
    return state.data
}
export default function useData(){
    const data = useSelector(getData) 
    return{data}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Back in my app file I used react hooks to pass this new data to my app.&lt;br&gt;
of course more Console.logs to follow all my data around...&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
const dispatch = useDispatch();
const data = useSelector(getData)
useEffect (() =&amp;gt; {
  console.log("a")
    dispatch(fetchQuestions());
  console.log("b")
},
 [dispatch]);
console.log(data)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I had an easy array of data to work with that I could pass as a prop throughout my app and call in the specific index.&lt;br&gt;
All of this made possible and easy by middleware! Of course for all of this to work within my index file I had to wrap my app component in Provider, define the store and give my app access 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;index.js
const store = createStore(quizReducer,applyMiddleware(thunk))
ReactDOM.render(
  &amp;lt;React.StrictMode&amp;gt;
    &amp;lt;Provider store={store}&amp;gt;
        &amp;lt;App /&amp;gt;
    &amp;lt;/Provider&amp;gt;
  &amp;lt;/React.StrictMode&amp;gt;,
document.getElementById('root')
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also updated my App.js to be able to pass the data through as props to each route.&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 className="App"&amp;gt;
     &amp;lt;Router&amp;gt;
      &amp;lt;Switch &amp;gt;
        &amp;lt;Route exact path="/"&amp;gt;
          &amp;lt;Home /&amp;gt;
        &amp;lt;/Route&amp;gt;
         &amp;lt;Route exact path="/quiz"&amp;gt; 
           &amp;lt;Quiz quotes={data}/&amp;gt; 
        &amp;lt;/Route&amp;gt;
        &amp;lt;Route 
        path='/Result'
        render={(props) =&amp;gt; (
        &amp;lt;Result {...props}/&amp;gt;)}
          /&amp;gt;
         &amp;lt;Route exact path="/highscore"&amp;gt;
          &amp;lt;Highscore highscore={data}/&amp;gt;
        &amp;lt;/Route&amp;gt;
      &amp;lt;/Switch&amp;gt;
      &amp;lt;/Router&amp;gt;
    &amp;lt;/div&amp;gt; 
  );

}

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

&lt;/div&gt;



&lt;p&gt;After my App file was set up with the routes to each component, and my index file was wrapping App with &lt;br&gt;
the Provider component making the Redux store available to these components, I started to build out the Quiz class which would be all of the main logic for the app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Quiz extends Component {
    state = {
        questionBank: [],
        score: 0,
        responses: 0
    };

    getQuestions = () =&amp;gt; {
        quiz().then(question =&amp;gt; {
            this.setState({
                questionBank: question
            });

        });
    };
    computeAnswer =
    (answer, correctAnswer) =&amp;gt; {
        if (answer === correctAnswer) {
      this.setState({
     score: this.state.score + 1
});
        }
      this.setState({
            responses: this.state.responses &amp;lt; 5 ? this.state.responses + 1 : 5
        })
    }
    componentDidMount(){
        this.getQuestions();
    }
    render() {
        return (
        &amp;lt;div className="container"&amp;gt;
        &amp;lt;div className="title"&amp;gt;IT IS THE OFFICE QUIZ.&amp;lt;/div&amp;gt;
        &amp;lt;div className="intro"&amp;gt; WHO SAID IT?&amp;lt;/div&amp;gt;
        {this.state.questionBank.length &amp;gt; 0 &amp;amp;&amp;amp; 
        this.state.responses &amp;lt; 5 &amp;amp;&amp;amp;
        this.state.questionBank.map(
            ({question, answers, correct, questionId}) =&amp;gt; (
        &amp;lt;QuestionBox question={question} options={answers} key={questionId} 
        selected={answer =&amp;gt; this.computeAnswer(answer,correct)}
        /&amp;gt; ) 
        )}
        {this.state.responses === 5 ? (&amp;lt;Result score={this.state.score}/&amp;gt;) : null}
        &amp;lt;/div&amp;gt; 
    )
}
}
ReactDom.render(&amp;lt;Quiz /&amp;gt;, document.getElementById("root"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;within this class I called my QuestionBox component and passed through the question, answers and selected props which would then allow the the answer to be selected and determine if it was correct!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const QuestionBox = ({question, options, selected}) =&amp;gt; {
  const [answer, setAnswer] = useState(options);
  return (
    &amp;lt;div className="questionBox"&amp;gt;
      &amp;lt;div className="question"&amp;gt;"{question}"&amp;lt;/div&amp;gt;
      {answer.map((text, index) =&amp;gt; (
        &amp;lt;button
          key={index}
          className="answerBtn"
          onClick={() =&amp;gt; {
              setAnswer([text]);
              selected(text);
          }}
        &amp;gt;
          {text}
        &amp;lt;/button&amp;gt;
      ))}
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once I had this working how I wanted by pushing the selected answer into its own array, I built out some CSS and logic for the home page and result page since this was primarily what was being displayed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;home.js

const Home = (props) =&amp;gt; {

    return (
        &amp;lt;div className="container"&amp;gt;
            &amp;lt;div className="welcome"&amp;gt;
            &amp;lt;div className="title"&amp;gt;
              &amp;lt;h1&amp;gt;IT IS THE OFFICE QUIZ.&amp;lt;/h1&amp;gt;
            &amp;lt;/div&amp;gt;
             &amp;lt;div className="intro"&amp;gt;
               &amp;lt;h2&amp;gt; Think you know who said it?&amp;lt;/h2&amp;gt;
                &amp;lt;h4&amp;gt;Test your 'The Office' quotes knowledge&amp;lt;/h4&amp;gt;
             &amp;lt;/div&amp;gt;
            &amp;lt;div className="home"&amp;gt;
               &amp;lt;h3&amp;gt; Its harder than you think... &amp;lt;/h3&amp;gt;
                &amp;lt;small&amp;gt;(that's what she said)&amp;lt;/small&amp;gt;
               &amp;lt;/div&amp;gt; 
                &amp;lt;button className="start"&amp;gt;
                    &amp;lt;Link to="/quiz"&amp;gt;Lets Play!&amp;lt;/Link&amp;gt;
                    &amp;lt;/button&amp;gt;
                    &amp;lt;button className="homescoreBtn"
                    onClick={props.highscore}&amp;gt;
                  &amp;lt;Link to="/highscore"&amp;gt;Highscores&amp;lt;/Link&amp;gt;
        &amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    )
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The results page showed the users score from setState and also rendered a PopUp component for a user to submit their name. I decided on a pop up as a challenge for myself, Pop up windows are every where in every day life and I wanted to take an opportunity to learn the basics!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Results.js 
const [showPopup, setShowPopup] = useState(false);
  useEffect(() =&amp;gt; {
    setTimeout(() =&amp;gt; setShowPopup(true), 2000);
}, []);

    return( 
         &amp;lt;div className="container"&amp;gt;
             { showPopup ? &amp;lt;PopUp highscore={`${props.location.state}`} /&amp;gt; : null }

              &amp;lt;div className="intro"&amp;gt;IT IS THE OFFICE QUIZ.&amp;lt;/div&amp;gt;
             &amp;lt;div className="home"&amp;gt;
               &amp;lt;h3&amp;gt; That wasn't so hard... &amp;lt;/h3&amp;gt;
                &amp;lt;small&amp;gt;(that's what she said)&amp;lt;/small&amp;gt;
               &amp;lt;/div&amp;gt; 
  &amp;lt;div&amp;gt;


      &amp;lt;/div&amp;gt;

        &amp;lt;div className="score-board"&amp;gt;
        &amp;lt;div className="score"&amp;gt;{`You answered ${props.location.state}/ 5 correct!`}&amp;lt;/div&amp;gt;
        &amp;lt;div className="gif"&amp;gt;
        &amp;lt;iframe className="gif" src="https://giphy.com/embed/8VrtCswiLDNnO" width="580" height="450" frameBorder="0" class="giphy-embed" allowFullScreen&amp;gt;&amp;lt;/iframe&amp;gt;&amp;lt;p&amp;gt;&amp;lt;a href="https://giphy.com/gifs/the-office-nbc-8VrtCswiLDNnO"&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="tryagain"&amp;gt;“Fool me once, strike one. Fool me twice, strike three.” -Michael Scott&amp;lt;/div&amp;gt;
        &amp;lt;button className="playBtn"
         onClick={props.playAgain}&amp;gt;
             &amp;lt;Link to="/quiz"&amp;gt;Play again?&amp;lt;/Link&amp;gt;
        &amp;lt;/button&amp;gt;
        &amp;lt;button className="scoreBtn"&amp;gt;
        &amp;lt;Link to="/"&amp;gt;Home&amp;lt;/Link&amp;gt;
         &amp;lt;/button&amp;gt;

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



Popup.js
const PopUp = (props) =&amp;gt; {

  const [open, setOpen] = useState(false);

  const initialFormData = {name: " ", highscore: props.highscore}
  const [formData, updateFormData] = useState(initialFormData);

  const handleChange = (e) =&amp;gt; {
    updateFormData({
      ...formData,
      [e.target.name]: e.target.value.trim()
    });
  };



    const handleSubmit = () =&amp;gt; {
    console.log(formData);
    fetch( "http://localhost:3000/scores", 
                    {
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(formData),
                    method: "post",
                     })
                     .then (console.log);

}

    return  (
        &amp;lt;nav className={open ? "open" : null}&amp;gt;
          &amp;lt;div className="popup"&amp;gt;
          &amp;lt;div className="popupform"&amp;gt; identity theft is not a joke.&amp;lt;/div&amp;gt; 
          &amp;lt;form className="formBtn" &amp;gt;
              &amp;lt;label&amp;gt; Name:
          &amp;lt;input type="text" name="name" id="name" onChange={handleChange} /&amp;gt;
             &amp;lt;/label&amp;gt;
            &amp;lt;/form&amp;gt;
                      &amp;lt;button className="formsubmit" value="submit"
        onClick={() =&amp;gt; {
        setOpen(!open);
        handleSubmit();
        }}
      &amp;gt;
          Submit
        &amp;lt;/button&amp;gt;


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

&lt;/div&gt;



&lt;p&gt;Creating the pop up component was also an easy way I could get the username data and score data together and post to the database.&lt;/p&gt;

&lt;p&gt;Finally to make sure all of these components had access to each other and the data I had to make sure all the files had the proper imports defined&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 React from "react";
import {BrowserRouter as Router, Switch, Route} from 'react-router-dom'
import "./assets/style.css";
import Quiz from "./components/quiz";
import Home from "./components/home";
import Highscore from "./components/highscore";
import Result from "./components/Result";
import { useEffect} from "react";
import {fetchQuestions} from './store/actions/action';
import {useDispatch, useSelector} from "react-redux"; 
import {getData} from "./store/selectors/selector";

index.js

import React from "react";
import ReactDOM from "react-dom";
import { Provider } from 'react-redux';
import { createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import quizReducer from './store/reducers/reducer'
import "./assets/style.css";
import App from "./App";

reducer.js

import { fetchSuccess, fetchRequest, fetchQuestions} from "../actions/action"
import useData from "../selectors/selector"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And so on throughout the rest of the components!&lt;br&gt;
The biggest challenge I faced during this project was passing data through props properly! It took some react doc reading to fully understand breaking down my project into thin vertical slices and working one problem at a time vs. wanting to just find a single solution to fix all my problems! taking the time to uncomment and console.log small things and to work at a slower pace to really grasp the flow of what parts of the data needed to be where and what state needed to be changed and updated is something that can only be learned from actually going through step by step on a project. I do love the ease and flexibility the React library provides.&lt;/p&gt;

</description>
      <category>react</category>
      <category>props</category>
      <category>redux</category>
      <category>thunk</category>
    </item>
    <item>
      <title>React: easy as "create-react-app"</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Wed, 30 Jun 2021 16:25:37 +0000</pubDate>
      <link>https://dev.to/kianajade42/react-easy-as-create-react-app-5ag4</link>
      <guid>https://dev.to/kianajade42/react-easy-as-create-react-app-5ag4</guid>
      <description>&lt;p&gt;Developers who have used React know how strong of a framework it is because of its flexibility and simplicity to &lt;br&gt;
improve performance. React is capable of handling DOM updates by grouping efficiently to provide less rendering and more specifically what needs to update and how.&lt;/p&gt;

&lt;p&gt;One of the most impressive features to me about React is its ability to behave so efficiently with minimal coding.&lt;br&gt;
 The reusable components can really keep even the most dynamic projects lightweight. To use React in its full entirety making sure you’re working in the most up to date version is the first and most important step. Of course this has been made easy for devs with the simple command of "create-react-app". Even though its tempting to just re-use old code for functionalities you may want to have in new projects it can work against you when trying to use newer react features. &lt;/p&gt;

&lt;p&gt;Another reason I think working in React is so enjoyable is the fact that for the most part we as people think in more "declarative programing" terms. &lt;/p&gt;

&lt;p&gt;when ordering a coffee you easily could say to the barista,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;grab a cup&lt;/p&gt;

&lt;p&gt;place the cup under the coffee spout&lt;/p&gt;

&lt;p&gt;Fill the cup&lt;/p&gt;

&lt;p&gt;add milk and sugar&lt;/p&gt;

&lt;p&gt;hand me the cup of coffee&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This isn’t how we tend to think though! &lt;br&gt;
instead you just say, "Coffee with milk and sugar!"; a simple declarative world! &lt;/p&gt;

&lt;p&gt;React offers a declarative approach which makes  it easy to use. When code is simple, elegant and easy to read it makes it easier to maintain with less to de-bug. Listing all the steps will work, but there is no need to with React, just like a barista, it’s capable of all the steps in between without explicitly specifying. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Before you decide on adding a Gem</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Wed, 30 Jun 2021 16:25:05 +0000</pubDate>
      <link>https://dev.to/kianajade42/before-you-decide-on-adding-a-gem-4n4d</link>
      <guid>https://dev.to/kianajade42/before-you-decide-on-adding-a-gem-4n4d</guid>
      <description>&lt;p&gt;2 things to remember when searching for gems to execute your projects are...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Security&lt;br&gt;
   To me this is probably the most important. As Im working on a project and doing my best to write efficient re-usable code I don’t want to waste time with ineffective gems! If a gem is not kept up to date with security features or has bugs those issues will be reflected in projects. you could potentially spend more time than anticipated restructuring or de-bugging simply because of a gem hasn't been kept up to date. There are plenty of resources on google to figure out what issues a gem might have as well as solutions from others on how they managed to fix gem issues.It’s always a good idea to check on how maintained a gem is before adding it to your project.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is it really needed?
I think about the concept that "gems are shiny"... there are plenty of gems that have amazing abilities and its easy to get caught up in the "bells" and "whistles" of dynamic gems. When faced with a problem it's sometimes so much easier to search for gems that can bundle and execute what you’re trying to accomplish, when really all it would take is a little extra effort to figure out a way to write better code. Part of the fun of creating dynamic applications or projects is the tinkering and re-writing and collaborating with others to solve an issue. Sometimes those gems are absolutely needed and the functionaries have been created for a reason, that doesn’t mean certain gems need to always be depended on. &lt;/li&gt;
&lt;/ol&gt;


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

</description>
    </item>
    <item>
      <title>Seeing code in everyday life</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Wed, 30 Jun 2021 16:24:29 +0000</pubDate>
      <link>https://dev.to/kianajade42/seeing-code-in-everyday-life-3kg6</link>
      <guid>https://dev.to/kianajade42/seeing-code-in-everyday-life-3kg6</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JYBD0nI8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y32txcswdqxn0s3i4d0p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JYBD0nI8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y32txcswdqxn0s3i4d0p.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;br&gt;
“Once you know some things, you can't unknow them. It's a burden that can never be given away.” -Alice Hoffman&lt;/p&gt;

&lt;p&gt;This concept has never felt so true since learning to program. Once you know how things work, you will always see whats going on "behind the scenes".  Being interested in what makes the applications and technology I use in my everyday  life is in no way a burden but very exciting and pushes me to want to expand my knowledge and learn how to create robust tech. &lt;/p&gt;

&lt;p&gt;I find myself always curious about if I could create the functionalities Im using on a website or a mobile app and if I can't think of it right away, I find myself running over potential solutions in my head and pushing myself to figure out how to create it or maybe spending some time searching stack overflow or other dev blogs about how they created something similar.&lt;/p&gt;

&lt;p&gt;Even something as mundane as driving from my home to the carwash can challenge my programming knowledge in multiple ways like the code behind...&lt;br&gt;
    1. The tech in my car&lt;br&gt;
    2. The stoplights regulating traffic (and a red-light cam I probably triggered)&lt;br&gt;
    3. Selecting the type of carwash I want on an automated screen when I arrive. &lt;br&gt;
    4. promptings on the screens around me telling me when to "stop", "go","place car in park"&lt;br&gt;
    5. The automated functions in the carwash controlling lights and other various functions&lt;/p&gt;

&lt;p&gt;In just 10 minutes out of my day Ive challenged myself to think about many functionalities I would have never previously in life even thought about existing.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSS fundamentals</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Wed, 30 Jun 2021 16:23:43 +0000</pubDate>
      <link>https://dev.to/kianajade42/css-fundamentals-3anf</link>
      <guid>https://dev.to/kianajade42/css-fundamentals-3anf</guid>
      <description>&lt;p&gt;CSS is my favorite programming blackhole to find myself in. It's easy to get lost for hours in the backend of a project that by the end of the day leaves you feeling tired and mentally drained. CSS is something I could easily &lt;br&gt;
sit and mess around with all day and still be excited about. I think it has to do with the fact there is an immediate result to see and can make your projects feel real and ready to launch even if there isn’t a single line written in the&lt;br&gt;
backend. I love the fact I can create the smallest color, font, layout, or margins/padding changes on something simple like a button and create a completely different feel for the user. &lt;/p&gt;

&lt;p&gt;On one of my first experiences with using CSS was in a coding workshop that I had a challenge to showcase what I had learned over the course. Things like linking sites, rendering photos, hover functions and more HTML and CSS. When working on this challenge I was definitely more focused on  making sure I was executing the functionalities rather than using CSS properties to my full advantage. Since my time at Flatiron and actually learning the full benefits of CSS, looking back on that project I realized there were so many advantages that I could have implicated.&lt;/p&gt;

&lt;p&gt;Rather than just using CSS as a styling option for font sizes and colors, which I did at the time, I've learned about using classes to render less code in my HTML and making it lightweight and easier to maintain and update. The accessibility of CSS gives more consistency in design elements like formatting and layout. Going forward in other projects I try to use CSS to my full advantage in the presentation and structure of my projects.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Object Oriented Programming</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Wed, 30 Jun 2021 16:22:42 +0000</pubDate>
      <link>https://dev.to/kianajade42/object-oriented-programming-4l33</link>
      <guid>https://dev.to/kianajade42/object-oriented-programming-4l33</guid>
      <description>&lt;p&gt;&lt;em&gt;"As humans, we’re constantly faced with myriad facts and impressions that we must make sense of. To do so, we must abstract underlying structure away from surface details and discover the fundamental relations at work. Abstractions reveal causes and effects, expose patterns and frameworks, and separate what’s important from what’s not. Object orientation provides an abstraction of the data on which you operate; moreover, it provides a concrete grouping between the data and the operations you can perform with the data—in effect giving the data behavior."&lt;br&gt;
—Object-Oriented Programming with Objective-C, Apple Inc.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;OOP is exactly what an inexperienced programmer might guess...programming structure that is oriented around objects.  smaller functionalities(objects) that can have specific behaviors(methods/attributes) bundle up in a way that executes a larger logical functionality(classes). Each object has values defined in its class resulting in a simple structure with less duplicate code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                     Basic structure of OOP:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Classes --&amp;gt; the top structure of methods/attributes
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Objects--&amp;gt; instances of a class with specific data&lt;br&gt;&lt;br&gt;
3.Methods--&amp;gt; behaviors/actions performed on data&lt;br&gt;&lt;br&gt;
4.Attributes--&amp;gt; information that is stored via the class       &lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                   Four pillars of OOP:
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inheritance--&amp;gt;child classes getting data from a parent class   &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Encapsulation--&amp;gt;displaying specific info from an object&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Abstraction--&amp;gt; accessing a specific object &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Polymorphism--&amp;gt; shared behavior of methods     &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Object Oriented programming really just means to think about the structure of the program at the beginning of your projects. Planning ahead of how to create simple objects and reusable classes will help with maintaining an easier flow of logic when working on a project. OOP is just one way to build an efficient data structure with reusability.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Data structures</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Wed, 30 Jun 2021 16:22:01 +0000</pubDate>
      <link>https://dev.to/kianajade42/data-structures-jdg</link>
      <guid>https://dev.to/kianajade42/data-structures-jdg</guid>
      <description>&lt;p&gt;what is it?&lt;/p&gt;

&lt;p&gt;Data structure at its most basic concept is just organization and storing information.&lt;br&gt;
However, there are a lot of ways to organize and not everyone prefers to organize the same.&lt;/p&gt;

&lt;p&gt;For my personal approach on grasping these concepts early on, I read blogs on how others developed concepts I was trying to accomplish. I quickly learned there was different approaches to storing data in efficient and easy to modify code. &lt;/p&gt;

&lt;p&gt;To familiarize myself with different data structures I read different source material and took notes in way that helped me understand and remember basic terms. The best way to learn was to actual "do".  I had a better understanding of effective data structures in one of the first projects at flatiron which was to build a CLI tic-tac-toe game. The curriculum of flatiron was easy to understand and very "user-friendly" for a beginner. However, I was interested in other ways to accomplish organizing different structures. From there going back and forth with refactoring and changing how to store arrays and objects really helped me understand how versatile data structures can be.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why software engineering?</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Wed, 30 Jun 2021 16:20:57 +0000</pubDate>
      <link>https://dev.to/kianajade42/why-software-engineering-1p5k</link>
      <guid>https://dev.to/kianajade42/why-software-engineering-1p5k</guid>
      <description>&lt;p&gt;why not software engineering... with the world changing and becoming more "tech-based" everyday the opportunity to learn and create seem endless. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         - My top 3 reasons-

           1.Opportunity 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;From Medtech, security, creating new applications or webpages or really anything that utilizes technology there is an opportunity  to explore many different areas.  I think about how my career-oriented interests might grow and change within the span of my career and how being a developer has the potential to provide me with the ability to adapt and explore different areas within the field. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      2. Job security 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;From a tech perspective, the world is not changing. As technology develops there will always be a demand for people who know how to program it all! Even if working for a tech corporation isn't the desire, having the knowledge to create webpages, apps or programs that are desired by entrepreneurs can always be an option. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Somewhere between creativity &amp;amp; knowledge 
Maybe it's where creativity and knowledge meet...From a personal perspective I have always been a strong artist and in academics. When thinking about a career path I always struggled to find a way to keep and develop both of these strengths.  The more I learned about different languages and about the ways different developers approach situations I begin to appreciate how much creativity along with a devs knowledge can (literally) make or break what is trying to be accomplished.  From the front-end and back-end the creativity and knowledge needed to bring it all together is an exciting field to find yourself in. &lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>A Simple CLI</title>
      <dc:creator>Kiana</dc:creator>
      <pubDate>Wed, 30 Jun 2021 15:46:41 +0000</pubDate>
      <link>https://dev.to/kianajade42/a-simple-cli-3dm6</link>
      <guid>https://dev.to/kianajade42/a-simple-cli-3dm6</guid>
      <description>&lt;p&gt;For my first project in Flatiron Software Engineering program, I had to create a command line application in Ruby. My application would be bundled into a package known as gem. My CLI uses Nokogiri to scrape facts about plants from a website and allows the user to choose a number to display a random fact. &lt;br&gt;
One of the main requirements for this projects was for a user to be able to go one level deep (a user can make a choice and based on that, make another selection and so on).&lt;/p&gt;

&lt;p&gt;This being my first CLI  I wanted to keep it as simple as possible to make sure I understood the flow of creating and developing the environment.  After creating a repository on github(github has plenty of information and resources on this), I created a gem by following the walkthrough on &lt;a href="https://guides.rubygems.org/make-your-own-gem/"&gt;https://guides.rubygems.org/make-your-own-gem/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;From there I ran bundler and connected my repo.  In the gemspec file had to add development dependencies for bundler, rake, rspec, and pry, and a general dependency for nokogiri. &lt;br&gt;
gemfile&lt;br&gt;
&lt;code&gt;gem "nokogiri"&lt;br&gt;
gem "pry"&lt;br&gt;
gem "rake", "~&amp;gt; 13.0"&lt;br&gt;
gem "rspec", "~&amp;gt; 3.0"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;gemspec&lt;br&gt;
&lt;code&gt;Gem::Specification.new do |spec|&lt;br&gt;
  spec.name          = "plantfacts"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Even with so many ideas of creating different features, the ability to create the start of the interface was the most important foundation to understand. Making sure I was solid on setting up and creating my gem and scraping the exact information is where I wanted my focus. After all of this foundation laid there is the ability to add features, separate concerns and provide more interactive functions for this CLI. &lt;/p&gt;

&lt;p&gt;I started with a basic flow diagram on the absolute minimum.&lt;/p&gt;

&lt;p&gt;1.prompting a user with a question&lt;br&gt;
2.receiving that input &lt;br&gt;
3.doing something with that input&lt;/p&gt;

&lt;p&gt;I decided to do a simple test of my ability to create a logical flow of the basic classes and methods I would be needing. These would just be objects calling on other objects in direct flow of events. The first being located in the bin folder under a file I created called plant.&lt;br&gt;
bin/plant&lt;br&gt;
&lt;code&gt;require ./lib/plantfacts/cli.rb&lt;br&gt;
Plantfacts::CLI.new.start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this folder I am requiring my cli.rb file which holds my class with all my app logic defined in it.&lt;br&gt;
cli.rb&lt;br&gt;
&lt;code&gt;class Plantfacts::CLI&lt;br&gt;
end&lt;/code&gt;&lt;br&gt;
Between these two files our connection for the logic of the app is made.&lt;br&gt;
The :: operator allows constants, instance methods and class methods defined within a class or module, to be accessed from anywhere outside the class or module.&lt;br&gt;
With this file I am also allowing the next event to happen,&lt;/p&gt;

&lt;p&gt;cli.rb&lt;br&gt;
&lt;code&gt;require_relative '../plantfacts'&lt;br&gt;
require_relative 'scraper'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Just these two lines of code are essential to operating. &lt;br&gt;
The first line points to the environment holding all my files.&lt;br&gt;
The second points directly to file of where my scraping is taking place, defining the .rb isn't necessary since the files its being called in is in the same folder. I still decided to separate this logic out so it was easier to work with in the future for debugging as I built out my project. Within this folder I had to give access to two very important things...&lt;br&gt;
scraper.rb&lt;br&gt;
&lt;code&gt;require 'nokogiri'&lt;br&gt;
require 'open-uri'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Nokogiri to be able to scrape the webpage of my choosing as well as 'open-uri' to directly call on the url.&lt;br&gt;
This small amount of code wouldn't work without requiring them both.&lt;br&gt;
scraper.rb&lt;br&gt;
&lt;code&gt;def facts&lt;br&gt;
 array=[]&lt;br&gt;
doc = Nokogiri::HTML(URI.open("https://www.funfactsabout.net/plant-facts/"))&lt;br&gt;
doc.css("ul.facts-list li").each do |list|&lt;br&gt;
array.push(list.text)&lt;br&gt;
 end&lt;br&gt;
 return array&lt;br&gt;
end&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;With the basics of my app environment flow set up I could start writing out exactly what I wanted to happen in my cli.&lt;br&gt;
 Thinking back to the flow of the user experience,&lt;br&gt;
I wanted to prompt a user with a question(if they wanted to learn about plants)&lt;br&gt;
receiving that input, which would then envoke a case statement deciding what to do with that input. &lt;br&gt;
These functions were all defined within the plantfacts class.&lt;br&gt;
cli.rb&lt;br&gt;
&lt;code&gt;def start&lt;br&gt;
     puts "Hi! do you like plants?[yes/no]:"&lt;br&gt;
     input=gets.strip&lt;br&gt;
     case input&lt;br&gt;
     when "no"&lt;br&gt;
        puts goodbye&lt;br&gt;
     when "yes"&lt;br&gt;
        puts plant&lt;br&gt;
     end&lt;br&gt;
end&lt;/code&gt;&lt;br&gt;
 from there my 'goodbye' and 'plant' methods allow the user to continue on with their experience until they are ready to exit the app. &lt;/p&gt;

&lt;p&gt;Although I don't intend to develop this basic cli any further or reuse the website/update the information later on, I wanted to execute good practices of creating re-able and re-usable code and understanding creating an environment within an app.&lt;/p&gt;

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