<?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: sarisgar28</title>
    <description>The latest articles on DEV Community by sarisgar28 (@sarisgar28).</description>
    <link>https://dev.to/sarisgar28</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%2F325407%2F44c497bd-91a9-498e-9881-dfc37b845dfc.JPG</url>
      <title>DEV Community: sarisgar28</title>
      <link>https://dev.to/sarisgar28</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarisgar28"/>
    <language>en</language>
    <item>
      <title>Continuing with React and Redux… I want to talk about REDUCERS! </title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Sun, 11 Apr 2021 22:24:26 +0000</pubDate>
      <link>https://dev.to/sarisgar28/continuing-with-react-and-redux-i-want-to-talk-about-reducers-3dj0</link>
      <guid>https://dev.to/sarisgar28/continuing-with-react-and-redux-i-want-to-talk-about-reducers-3dj0</guid>
      <description>&lt;p&gt;Reducers are functions that take the current STATE and ACTION as arguments returning a NEW STATE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const expenseReducer = (state = [], action) =&amp;gt; {
   switch (action.type){
       case "SET_EXPENSE":
       return action.payload.expense || state
       case "ADD_EXPENSE":
           return [...state,action.payload]
        case "REMOVE_EXPENSE":
           return state.filter(expense =&amp;gt; expense !== 
 action.payload)
       default:
       return state

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

&lt;/div&gt;



&lt;p&gt;(Make sure to pass the initial state with the right data structure) &lt;/p&gt;

&lt;p&gt;An important thing about reducers is they are pure functions meaning:&lt;br&gt;
Pure functions are only determined by their input values.&lt;br&gt;
Pure functions have no side effects, meaning they don’t have any effect outside the function, it will only return a value.&lt;/p&gt;

&lt;p&gt;For separations of concerns you normally do one reducer by component, so if we have more than one (you most likely will) we can use something call “combineReducers()” method and it will go on a separate folder such as index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;frontend/src/redux/reducer/index.js


import userReducer from './userReducer'
import expenseReducer from './expenseReducer'




export default combineReducers({
   user: userReducer,
   expenses: expenseReducer


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

&lt;/div&gt;



&lt;p&gt;The structure for redux is to split the state into multiple slices or domains by key and provide a separate reducer to manage each individual slice of data as the redux docs say, combineReducers method is not required but it is useful to put all your data together.&lt;/p&gt;

&lt;p&gt;The combineReducers helper function turns an object whose values are different reducing functions into a single reducing function you can pass to createStore. Passing the state as objects gives them a key and a value, you can control state key names by using different keys in the passed value.&lt;/p&gt;

&lt;p&gt;You can read more about it here: &lt;br&gt;
 &lt;a href="https://redux.js.org/api/combinereducers"&gt;https://redux.js.org/api/combinereducers&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;HAPPY CODING! :) &lt;/p&gt;

</description>
      <category>redux</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>REACT-REDUX </title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Sun, 11 Apr 2021 20:10:17 +0000</pubDate>
      <link>https://dev.to/sarisgar28/react-redux-349f</link>
      <guid>https://dev.to/sarisgar28/react-redux-349f</guid>
      <description>&lt;p&gt;I've made it! I am graduating as a Full Stack developer! I want to explain one of the most important things I came across with my last project with flatiron.&lt;br&gt;
React provides two mechanisms for providing data to components PROPS and STATE. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Props allow the parent component to pass attributes to a child component. &lt;/li&gt;
&lt;li&gt;State is local and encapsulated within the component can change at any time in the component's lifecycle.
Redux provides a well structure architecture system for managing state but first...
WHAT IS REDUX?
Redux is a predictable state container for Javascript. It can be run in different environments such as Client, Server and Native. 
Let me explain in more depth what these models are.
Models are a web development terms that describe where the application runs.&lt;/li&gt;
&lt;li&gt;Client side: refers to everything in a web application that is displayed or takes place on the client (end user device) this includes what the user sees such as texts, images and the rest of UI.&lt;/li&gt;
&lt;li&gt;Server side: much like client side, server side means everything that happens on the server instead of on the client.&lt;/li&gt;
&lt;li&gt;Native: sometimes called a public client, this is intended to be a client app that runs on a pc or device and with which the user interacts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more depth on these topics go to these links: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cloudflare.com/learning/serverless/glossary/client-side-vs-server-side/"&gt;https://www.cloudflare.com/learning/serverless/glossary/client-side-vs-server-side/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/50338317/what-is-the-difference-between-a-native-application-server-application-when-ta"&gt;https://stackoverflow.com/questions/50338317/what-is-the-difference-between-a-native-application-server-application-when-ta&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Taking up from where I left off on redux.&lt;br&gt;
What is Redux Connect? &lt;br&gt;
react-redux package provides react binding for the redux state container making a "GLOBAL STATE" but separating react application component bases on their connections to redux store.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {connect} from 'react-redux'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Presentational Components: are only concerned with how things look and are not aware of the redux state.&lt;/li&gt;
&lt;li&gt;Container Components: are responsible for how things work and are fully aware of the redux state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They are often created using react-redux and may dispatch redux actions. &lt;/p&gt;

&lt;p&gt;Example of Redux actions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {ExpenseRequest} from '../../services/api'
 //add 
export const getExpense = () =&amp;gt; {
   return (dispatch) =&amp;gt; {
       ExpenseRequest().then(response =&amp;gt; {
       dispatch({type: 'ADD_EXPENSE', payload: response})
     })
   }
 }

 // remove

export const removeExpense = () =&amp;gt; {
   return (dispatch) =&amp;gt; {
       ExpenseRequest().then(response =&amp;gt; {
       dispatch({type: 'REMOVE_EXPENSE', payload: response})
     })
   }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How to connect actions with react, is very simple you will have to create a mapStateToProps() and mapDispatchToProps() methods in order to connect these two. But first you will have to set up some Middlewares such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux'
import reducer from './redux/reducer/index'
import thunk from 'redux-thunk'
import { Navbar } from 'react-bootstrap';
const store = createStore(reducer, applyMiddleware(thunk))
ReactDOM.render(
  &amp;lt;Provider store= {store}&amp;gt;
    &amp;lt;App /&amp;gt;
    &amp;lt;Navbar/&amp;gt;
  &amp;lt;/Provider&amp;gt;,
  document.getElementById('root')
);
reportWebVitals();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; wraps the react app and makes the redux state available to all container components in the application hierarchy.&lt;br&gt;
I hope this blog post was explanatory if you need more information please go to the redux documents.&lt;br&gt;
link = &lt;a href="https://react-redux.js.org/introduction/getting-started"&gt;https://react-redux.js.org/introduction/getting-started&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading and happy coding!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>redux</category>
    </item>
    <item>
      <title>How to Use Fetch to make Ajax calls in JavaScript</title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Sun, 07 Feb 2021 21:11:57 +0000</pubDate>
      <link>https://dev.to/sarisgar28/how-to-use-fetch-to-make-ajax-calls-in-javascript-5aem</link>
      <guid>https://dev.to/sarisgar28/how-to-use-fetch-to-make-ajax-calls-in-javascript-5aem</guid>
      <description>&lt;p&gt;Fetch is an interface to make requests and responses from a backend to frontend.&lt;/p&gt;

&lt;p&gt;The requests are sent as GET by default.To send POST/PATCH/DELETE/PUT you can use a method property as part of options it can take values such as:&lt;/p&gt;

&lt;p&gt;METHOD: GET/POST/PATCH&lt;br&gt;
HEADERS: HEADER OBJECT&lt;br&gt;
MODE: SUCH AS CORS, NO-CORS, SAME ORIGIN(depends on your browser)&lt;/p&gt;

&lt;p&gt;EXAMPLE: &lt;/p&gt;

&lt;p&gt;postUser = body =&amp;gt; fetch(this.usersURL, {&lt;br&gt;
   method: "POST",&lt;br&gt;
   headers: this.headers,&lt;br&gt;
   body: JSON.stringify(body)&lt;br&gt;
 }).then(this.parseJSON)&lt;/p&gt;

&lt;p&gt;There’s an umbrella called AJAX(Asynchronous Javascript and Xml)&lt;br&gt;
Using Ajax and Fetch IS flexible and easy to use because of its syntax and structure, it’s supported by modern browsers and ES6 Javascript(so make sure to read the requirements)&lt;/p&gt;

&lt;p&gt;Some definitions I think are useful to share are:&lt;/p&gt;

&lt;p&gt;XML: Lets you convert data to JSON to your device.&lt;/p&gt;

&lt;p&gt;JSON: JavaScript Object Notation is a syntax to serializing objects, arrays, numbers, strings, booleans and NULL &lt;/p&gt;

&lt;p&gt;Calling Fetch returns a promise for example: &lt;/p&gt;

&lt;p&gt;fetchScores = () =&amp;gt; fetch(this.scoresURL).then(this.parseJSON)&lt;/p&gt;

&lt;p&gt;Some methods you should know are:&lt;br&gt;
JSON(): Resolves the promise &lt;/p&gt;

&lt;p&gt;CLONE(): Creates a clone of the response &lt;/p&gt;

&lt;p&gt;arrayBuffer(): Returns a promise that resolves with a generic fixed length raw binary data buffer(temporarily stores data while it is being moved from one place to another)&lt;/p&gt;

&lt;p&gt;SUMMARY:&lt;/p&gt;

&lt;p&gt;Javascript fetch request-responses are used to make asynchronous HTTP requests, using as much clearer code and delivering flexible features to make requests to servers from web browsers.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>HAS_MANY THROUGH</title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Fri, 11 Dec 2020 20:57:00 +0000</pubDate>
      <link>https://dev.to/sarisgar28/hasmany-through-16nc</link>
      <guid>https://dev.to/sarisgar28/hasmany-through-16nc</guid>
      <description>&lt;p&gt;HAS_MANY THROUGH ASSOCIATIONS!&lt;/p&gt;

&lt;p&gt;I finally got to Rails!... I personally feel has_many through associations need a deeper explanation than what you find in &lt;a href="https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association"&gt;https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;As my project has these types of associations, I thought it would be of great value to whoever reads my blog posts. &lt;br&gt;
Here is my schema: &lt;/p&gt;

&lt;p&gt;ActiveRecord::Schema.define(version: 2020_11_23_171000) do&lt;/p&gt;

&lt;p&gt;create_table "landmarks", force: :cascade do |t|&lt;br&gt;
    t.string "name"&lt;br&gt;
    t.string "city"&lt;br&gt;
    t.string "country"&lt;br&gt;
    t.text "description"&lt;br&gt;
    t.datetime "created_at", precision: 6, null: false&lt;br&gt;
    t.datetime "updated_at", precision: 6, null: false&lt;br&gt;
  end&lt;/p&gt;

&lt;p&gt;create_table "reviews", force: :cascade do |t|&lt;br&gt;
    t.string "review"&lt;br&gt;
    t.integer "landmark_id"&lt;br&gt;
    t.integer "user_id"&lt;br&gt;
    t.datetime "created_at", precision: 6, null: false&lt;br&gt;
    t.datetime "updated_at", precision: 6, null: false&lt;br&gt;
  end&lt;/p&gt;

&lt;p&gt;create_table "users", force: :cascade do |t|&lt;br&gt;
    t.string "username"&lt;br&gt;
    t.string "email"&lt;br&gt;
    t.string "password_digest"&lt;br&gt;
    t.datetime "created_at", precision: 6, null: false&lt;br&gt;
    t.datetime "updated_at", precision: 6, null: false&lt;br&gt;
  end&lt;/p&gt;

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

&lt;p&gt;What has_many through does is create a join table by connecting, in this case, three models which will work as many to many relations. In  my join table above is “REVIEWS”  containing a “landmark_id” and “user_id” as attributes which are called FOREIGN KEYS. These keys are many to many relations to my other two models “USERS” and “LANDMARKS”.&lt;/p&gt;

&lt;p&gt;Once you have your migrations set up, you move into your models by creating the association itself. &lt;/p&gt;

&lt;p&gt;LANDMARK CLASS: &lt;/p&gt;

&lt;p&gt;class Landmark &amp;lt; ApplicationRecord&lt;br&gt;
   has_many :reviews, dependent: :destroy&lt;br&gt;
   has_many :users, through: :reviews&lt;br&gt;
   scope :find_name, -&amp;gt; (name) {find_by(name: name)}&lt;/p&gt;

&lt;p&gt;validates :name, presence: true&lt;br&gt;
   validates :city, presence: true&lt;br&gt;
   validates :country, presence: true&lt;br&gt;
   validates :description, presence: true&lt;/p&gt;

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

&lt;p&gt;REVIEW CLASS:&lt;/p&gt;

&lt;p&gt;class Review &amp;lt; ApplicationRecord&lt;br&gt;
    belongs_to :user&lt;br&gt;
   belongs_to :landmark&lt;br&gt;
   validates :review, presence: true&lt;/p&gt;

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

&lt;p&gt;USER CLASS:&lt;/p&gt;

&lt;p&gt;class User &amp;lt; ApplicationRecord&lt;/p&gt;

&lt;p&gt;has_secure_password&lt;/p&gt;

&lt;p&gt;has_many :reviews&lt;br&gt;
   has_many :landmarks, through: :reviews&lt;/p&gt;

&lt;p&gt;validates :username, presence: true, uniqueness: :true&lt;br&gt;
   validates :email, presence: true, uniqueness: :true&lt;/p&gt;

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

&lt;p&gt;The drawing above is my migrations representation, which is what I expressed on my schema.&lt;br&gt;
Active Record is pretty magical and by doing this association, when you see  the model USER has_many :landmarks through reviews  means that the instances of our USER now responds to a method called Landmarks. This will return a collection of LANDMARKS that share a REVIEW with the USER. &lt;/p&gt;

&lt;p&gt;HAPPY CODING! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>ActiveRecord Associations </title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Mon, 28 Sep 2020 16:14:16 +0000</pubDate>
      <link>https://dev.to/sarisgar28/activerecord-associations-149o</link>
      <guid>https://dev.to/sarisgar28/activerecord-associations-149o</guid>
      <description>&lt;p&gt;Active Record associations are a convenient way to declare methods through different models, from your database to columns and tables.&lt;br&gt;
These examples are based on my last sinatra project with Flatiron School.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Pet &amp;lt; ActiveRecord::Base
    belongs_to :user
    end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This is displayed as a singular.&lt;/li&gt;
&lt;li&gt;Sets up a one on one connection with another Model, in this 
case PETS to USER&lt;/li&gt;
&lt;li&gt;Uses a foreign key user_id&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  METHODS ADDED BY BELONGS_TO
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.association=(associate)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The association= assigns to associate (user) object to the &lt;br&gt;
(pet) object which means extracting the primary key (user_id) from my table and setting the foreign key to the same value.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pets&lt;/th&gt;
&lt;th&gt;User&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;user_id&lt;/td&gt;
&lt;td&gt;username&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;name&lt;/td&gt;
&lt;td&gt;password&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;age&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;notes&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This table above is an explanation of how my tables are a ONE to ONE relationship as the record contains exactly one instance of another Model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.build.association(attribute={})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This association returns a new object of the associated type. The object will be an instance from the passed attribute and the link through this object's foreign key will be set but &lt;br&gt;
NOT SAVED.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This association returns the new object of the associated type. It will be instantiated from the passed attributes,then linked to the object's foreign key, and finally be set. Once it passes validations it will BE SAVED.&lt;/p&gt;

&lt;h2&gt;
  
  
  HAS_MANY :PETS
&lt;/h2&gt;



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

    has_many :pets
end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is called the collection method and returns a relation of all the associated objects(pets). If there are no associated objects it will return an empty relation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.collection(object)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method makes the collection contain only the supplied objects by adding and deleting as appropriate. The changes are 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;.collection.build(User.pets.build)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method returns a single or an array of new objects of the associated type. The objects will be instantiated from the passed attributes and then linked through their foreign key which will be created but NOT SAVED.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.collection.create(User.pets.create)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method will create a single or an array of new objects. The objects will be instantiated from the passed attributes, and then linked to the foreign key. Once it passes validations IT WILL BE SAVED.&lt;/p&gt;

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

</description>
      <category>ruby</category>
      <category>codenewbie</category>
      <category>womenintech</category>
    </item>
    <item>
      <title>RESTful Routes</title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Sun, 27 Sep 2020 22:34:06 +0000</pubDate>
      <link>https://dev.to/sarisgar28/restful-routes-3in</link>
      <guid>https://dev.to/sarisgar28/restful-routes-3in</guid>
      <description>&lt;p&gt;Hi there, I will be writing about RESTFUL ROUTES  by explaining each of the verbs and actions within my sinatra web app.&lt;/p&gt;

&lt;p&gt;Restful routes are a design pattern that allows easy data manipulation, as developers and users can recognize the code and understand it better. &lt;br&gt;
Restful routes provides mapping between HTTP verbs, such as GET, POST, PUT, PATCH and DELETE to controller actions (Create, Read, Update, Delete) very well known as CRUD.&lt;br&gt;
Instead of depending on URL to indicate where you are in your browser, Restful routes uses HTTP REQUESTS to send and receive actions from the USER. These requests work with my application on receiving a request, examining it, as well as identifying the HTTP method and URL in my controller and executing the code with the action to give a response to the USER.&lt;/p&gt;
&lt;h2&gt;
  
  
  PUT-PATCH-DELETE
&lt;/h2&gt;

&lt;p&gt;These are hidden requests sent by POST request to the browser, as HTML is stateless which means it supports GET and POST requests only. To perform the three actions above, we use Rack::MethodOverride into your Config.ru file as "use Rack::MethodOverride" middleware. We have to use a post method in the html form to simulate a request with a non supported method in order to make this work, you will have to type&lt;br&gt;
&lt;br&gt;
  &lt;code&gt;&amp;lt;input type="hidden"&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 Following an&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;&amp;lt;input type="hidden" name="_method"&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 The method's name has to be included as the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form method="post" action="/logout"&amp;gt;
  &amp;lt;input  type="hidden" name="_method" value="DELETE"&amp;gt;
  &amp;lt;input type="submit" value="Log out"&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will explain each action I've created on my web app one by one.&lt;/p&gt;

&lt;p&gt;INDEX ACTION&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get '/pets' do 
        authenticate 
        @pets = current_user.pets.all
        erb :'/pets/dashboard'
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This responds to a GET request to the route '/pets' and is the Index Action; it allows the view access to all the User's pets in the database through the instance variable @pets and render it to my erb :'/pets/dashboard'&lt;/p&gt;

&lt;p&gt;NEW ACTION&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This is a GET request to load the form to create a new pet.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;CREATE ACTION
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;post '/pets' do
      @pet = Pet.new(name: params[:name],age: 
          params[:age],notes: params[:notes])
      if @pet.save
        current_user.pets &amp;lt;&amp;lt; @pet
        redirect "/pets/#{@pet.id}"
      else  
        erb :'/pets/new'
      end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This responds to a POST request and creates a new pet based on the params and saves it to the database. Once the pet is created this action redirects to show.erb.&lt;/p&gt;

&lt;p&gt;SHOW ACTION&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; get '/pets/:id' do
      @pet = Pet.find_by(id: params[:id])
      erb :'/pets/show'
    end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The controller action responds to a GET request to the path '/pets/:id' as this route is a dynamic one it will access the pet by its ID in the view through the params hash.&lt;/p&gt;

&lt;p&gt;EDIT ACTION&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get '/pets/:id/edit' do
        @pet = Pet.find_by(id: params[:id])
        dont_edit 
        erb :'/pets/edit'
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This route loads the edit form in the browser by making a GET request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;patch '/pets/:id' do 
        @pet = Pet.find_by(id: params[:id])
       dont_edit
        @pet.update(name: params[:name],age: params[:age],notes: params[:notes])
        @pet.save
        redirect '/pets'
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After submitting the form, the PATCH requests to the path '/pets/:id', first it will pull the pet by name, age and notes through params, then saves the pet and redirects to the dashboard '/pets'&lt;/p&gt;

&lt;p&gt;DELETE ACTION&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;delete '/pets/:id' do 
        @pet = Pet.find_by(id: params[:id])
        dont_edit
        @pet.destroy
        redirect '/pets'
    end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This form is submitted via a DELETE request to the path '/pets/:id', this action finds the pet by the ID in the database, deletes it and redirects to '/pets'&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>codenewbie</category>
      <category>womenintech</category>
      <category>html</category>
    </item>
    <item>
      <title>Ruby on Sinatra</title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Sun, 20 Sep 2020 20:01:34 +0000</pubDate>
      <link>https://dev.to/sarisgar28/ruby-on-sinatra-5398</link>
      <guid>https://dev.to/sarisgar28/ruby-on-sinatra-5398</guid>
      <description>&lt;p&gt;Hi! &lt;br&gt;
what a crazy year... I started this journey with Flatiron School on March 2020 right when the pandemic hit and IT HAS BEEN HARD!&lt;br&gt;
I am very proud of myself I am keeping up with my learning, I created a web app with Ruby with Sinatra and Active Record and it turned out pretty decent&lt;br&gt;
I would like to talk about what I've learned so far with this project.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;MVC it's basically separation of concerns where your files are going to go super organized and if you have to debug or come back to your code will be easier to find.
Models, Views and Controllers &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Models:&lt;/strong&gt; Where the logic is, they are generally written by Ruby Classes, connecting the databases to persist it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Views:&lt;/strong&gt; Where the User and the web app connect, they are written as &lt;strong&gt;.erb&lt;/strong&gt; files by HTML and CSS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Controllers:&lt;/strong&gt; Are written in Ruby and consist of 'routes' that take requests sent from the browser, run code based on those requests by using models, and then render the .erb (views) files for the user to see.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PARAMS[:]=&lt;/strong&gt; It takes your input from a form using a hash to create new objects from my application to my controllers file using HTTP requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REST:&lt;/strong&gt; Representational State of Transfer, an architectural style design for distributed hypermedia.&lt;/p&gt;

&lt;p&gt;I also applied many HTTP request methods to my project such as, POST(read), GET(read),UPDATE(edit) and DESTROY.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ACTIVE-RECORD BASE:&lt;/strong&gt; It gives access to a number of methods to a number of methods that assist in working with the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SINATRA ACTIVE-RECORD:&lt;/strong&gt; Extends Sinatra with methods and Rake Tasks to deal with sqlite3 database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Validations:&lt;/strong&gt; I used &lt;strong&gt;authenticate&lt;/strong&gt; so my users have exclusive access to their data, as well as securing my password &lt;strong&gt;has_secure_password&lt;/strong&gt; by using BCRYPT GEM.&lt;/p&gt;

&lt;p&gt;I hope this post gives some value. &lt;/p&gt;

&lt;p&gt;My project will be available right below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sarisgar28/pet_tracker"&gt;https://github.com/sarisgar28/pet_tracker&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>leadership</category>
      <category>womenintech</category>
    </item>
    <item>
      <title>Sinatra Ruby Web App</title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Sun, 05 Jul 2020 20:00:48 +0000</pubDate>
      <link>https://dev.to/sarisgar28/sinatra-ruby-with-crud-4d7</link>
      <guid>https://dev.to/sarisgar28/sinatra-ruby-with-crud-4d7</guid>
      <description>&lt;p&gt;Hi Guys! &lt;br&gt;
This has been crazy times, for the world and as a student is been the hardest months in terms of learning to code... &lt;br&gt;
I am a student in Flatiron School and for our second module we need to create a Sinatra Web App using MVC which stands for MODELS, VIEWS AND CONTROLLERS!&lt;br&gt;
I've noticed that my previous post was a little meh on showing my experience doing this application so I will share a little more on this post.&lt;br&gt;
I am going to share some of my files from my app hoping it will be helpful for you. In my application I am using,Sinatra Active Record, MVC, CRUD as well as uniqueness of validation for user login attribute. &lt;br&gt;
First I would like to share my Gemfile...&lt;/p&gt;

&lt;p&gt;gem "sinatra", "~&amp;gt; 2.0"&lt;/p&gt;

&lt;p&gt;gem "require_all", "~&amp;gt; 3.0"&lt;/p&gt;

&lt;p&gt;gem "pry", "~&amp;gt; 0.13.1"&lt;/p&gt;

&lt;p&gt;gem "shotgun", "~&amp;gt; 0.9.2"&lt;/p&gt;

&lt;p&gt;gem "activerecord", "~&amp;gt; 6.0"&lt;/p&gt;

&lt;p&gt;gem "sinatra-activerecord", "~&amp;gt; 2.0"&lt;/p&gt;

&lt;p&gt;gem "sqlite3", "~&amp;gt; 1.4"&lt;/p&gt;

&lt;p&gt;gem "rake", "~&amp;gt; 13.0"&lt;/p&gt;

&lt;p&gt;gem "bundler", "~&amp;gt; 2.1"&lt;/p&gt;

&lt;p&gt;gem "bcrypt", "~&amp;gt; 3.1"&lt;/p&gt;

&lt;p&gt;You will need to set up your controllers as well as your views to make sure your app is working, make sure you use Session Secret and enable your Sessions just like this code below.&lt;/p&gt;

&lt;p&gt;class ApplicationController &amp;lt; Sinatra::Base &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set :views, -&amp;gt;{File.join(root,'../views')}
enable :sessions
set :session_secret, ENV["SESSION_SECRET"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;end &lt;br&gt;
Once you have this you can get started with your SINATRA CRUD, which stands for Create, Read, Update and Destroy.&lt;/p&gt;

&lt;p&gt;class SessionsController &amp;lt; ApplicationController&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get '/login' do 
    erb :"sessions/login"
end 

get '/signup' do 
    erb :'sessions/signup'
end 

post '/signup' do
    @user = User.new(username: params[:username], password: params[:password])
    if @user.save 
        session[:user_id] = @user.id 
        redirect'/cocktails'
    else
     erb :"sessions/signup"
    end
end 

post '/login' do 
     user = User.find_by(username: params[:username])
    if user &amp;amp;&amp;amp; user.authenticate(params[:password])
        session[:user_id] = user.id
        redirect'/cocktails'
    else  
        @error = "Invalid Username or Password"
        erb :"sessions/login"

    end 
end 

delete '/logout' do 
    session.clear
    redirect '/home'
    erb :'/cocktails'
end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;end &lt;br&gt;
I've been RESTful in my code because is a requirement on my project, I think is a good practice to follow but is your choice to whether you use it or not.&lt;br&gt;
I am happy to share my GitHub page so you guys can see my complete project, I hope this post is somewhat helpful to you.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sarisgar28/sinatra_project"&gt;https://github.com/sarisgar28/sinatra_project&lt;/a&gt;&lt;/p&gt;

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

</description>
      <category>codenewbie</category>
      <category>ruby</category>
    </item>
    <item>
      <title>MY VERY FIRST CLI APP</title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Tue, 05 May 2020 21:44:38 +0000</pubDate>
      <link>https://dev.to/sarisgar28/my-very-first-cli-app-1fke</link>
      <guid>https://dev.to/sarisgar28/my-very-first-cli-app-1fke</guid>
      <description>&lt;p&gt;I have gotten through my 8th week during my bootcamp experience. Oh man! It’s been a rollercoaster… As I mentioned on my first blog post I started my bootcamp with Flatiron School knowing literally zero about tech and all this different world. Now I know the basics of Ruby, It’s a technical language for sure and I have to say it has not been easy for me to learn this! But I have something really cool  to share and that is I have built my first CLI application! &lt;/p&gt;

&lt;p&gt;I AM VERY EXCITED!&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://player.vimeo.com/video/233979216" width="710" height="399"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now let me tell you how fascinating is my Movie Tracker Command Line Interface Application, let me take a step back and tell you about what were my  project requirements. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I Gathered Data from an API (Application Programing Interface)
&lt;/li&gt;
&lt;li&gt;Create a CLI application(how easy!) &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s start!  So where did I start? I needed an API so I started my research and found a website called RapidAPI, you can find any type of API you’d like, I thought making a Movie Tracker, I thought is a good idea for my very first CLI app, It was going to be simple and a very good way to provide clean code.&lt;/p&gt;

&lt;p&gt;So now the cool stuff begins! &lt;/p&gt;

&lt;p&gt;I started with my BUNDLER GEM set up, I went to my XCODE terminal and typed “bundle gem movie_tracker” and it created most of my files, once my workspace opened on my VSCO I created my three class.rb. Once I started putting code on the files I was getting a better idea of what I was creating...Is a very simple not too long application, I tried to be as clean but creative on my code always giving the right commands to it. I feel very accomplished with what i’ve done. My Movie Tracker CLI app, searches for any type of movie you want to see, first you will see a WELCOME message, followed by two more messages “Get ready to find a movie!” and “Enter a movie title or type exit” if you look for a title you will find the movie you want to watch plus some extra information about the movie like  Type, Year and IMDb; after you see this information you get to have the option to select one movie from the options you have, you will give the number of the option to the Movie you want to see and more information about it will be display such as Plot, Genres, Director, Actors and Runtime after that my loop keeps going and you can either look for another Movie or Exit the search. &lt;/p&gt;

&lt;p&gt;You can see my code here : &lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/sarisgar28"&gt;
        sarisgar28
      &lt;/a&gt; / &lt;a href="https://github.com/sarisgar28/movie_tracker"&gt;
        movie_tracker
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      CLI PROJECT 
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Thank you for reading and Happy Coding!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Sara's weekly progress</title>
      <dc:creator>sarisgar28</dc:creator>
      <pubDate>Tue, 28 Jan 2020 15:08:17 +0000</pubDate>
      <link>https://dev.to/sarisgar28/sara-s-weekly-progress-3gm5</link>
      <guid>https://dev.to/sarisgar28/sara-s-weekly-progress-3gm5</guid>
      <description>&lt;p&gt;Hi Everyone!&lt;br&gt;
My name is Sara, I am a colombian living in NYC!&lt;/p&gt;

&lt;p&gt;I went to school for architecture,I have a big passion about it, it’s my hobby,However when I tried to look for work the expectation I had it was totally different from reality, I learned how to be creative and push my imagination to the highest level, that is why I started to learn about technology as implementing both is a great way to manifest your ideas into incredible applications.I love challenges, languages and I believe I will become great at this.  Please take a look at my progress in Flatiron School!&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>productivity</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
