<?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: arbarrington</title>
    <description>The latest articles on DEV Community by arbarrington (@arbarrington).</description>
    <link>https://dev.to/arbarrington</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%2F905474%2Ffebeaa79-977c-4859-9e8f-66eadd112bbe.jpg</url>
      <title>DEV Community: arbarrington</title>
      <link>https://dev.to/arbarrington</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arbarrington"/>
    <language>en</language>
    <item>
      <title>Ternary Operators for App with two User Types</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Fri, 18 Nov 2022 18:26:02 +0000</pubDate>
      <link>https://dev.to/arbarrington/ternary-operators-for-app-with-two-user-types-2oeh</link>
      <guid>https://dev.to/arbarrington/ternary-operators-for-app-with-two-user-types-2oeh</guid>
      <description>&lt;p&gt;I created an app where users are either a farmer or consumer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;producer&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Favorite&lt;/span&gt; &lt;span class="nx"&gt;Producers&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Consumer&lt;/span&gt; &lt;span class="nx"&gt;Analytics&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;SalesByMonth&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;partialOrderComplete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;partialOrderComplete&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;myOrders&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;myOrders&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;myOrdersOut&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;myOrdersOut&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Cookies and Sessions</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Thu, 20 Oct 2022 21:20:31 +0000</pubDate>
      <link>https://dev.to/arbarrington/cookies-and-sessions-4a7h</link>
      <guid>https://dev.to/arbarrington/cookies-and-sessions-4a7h</guid>
      <description>&lt;p&gt;Since cookies are such an important part of most web applications, Rails has excellent support for cookies and sessions baked in. Unfortunately for us, when you create a new application in API mode with rails new appname --api, the code needed for working with sessions and cookies in the controller is excluded by default.&lt;/p&gt;

&lt;p&gt;To add session and cookie support back in, we need to update our application's configuration in the config/application.rb file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# config/application.rb
module MyApp
  class Application &amp;lt; Rails::Application
    config.load_defaults 6.1
    # This is set in apps generated with the --api flag, and removes session/cookie middleware
    config.api_only = true

    # Must add these lines!
    # Adding back cookies and session middleware
    config.middleware.use ActionDispatch::Cookies
    config.middleware.use ActionDispatch::Session::CookieStore

    # Use SameSite=Strict for all cookies to help protect against CSRF
    config.action_dispatch.cookies_same_site_protection = :strict
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will add in the necessary middlewareLinks to an external site. for working with sessions and cookies in our application.&lt;/p&gt;

&lt;p&gt;To access the cookies hash in our controllers, we also need to include the ActionController::Cookies module in our ApplicationController:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# app/controllers/application_controller.rb
class ApplicationController &amp;lt; ActionController::API
  include ActionController::Cookies
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Rails Validation</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Wed, 12 Oct 2022 20:43:13 +0000</pubDate>
      <link>https://dev.to/arbarrington/rails-validation-343c</link>
      <guid>https://dev.to/arbarrington/rails-validation-343c</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;validates :name, presence: true
validates :name, length: { minimum: 2 }
validates :email, uniqueness: true
validates :not_a_robot, acceptance: true, message: "Humans only!"
validates :year, numericality: {
    greater_than_or_equal_to: 1888,
    less_than_or_equal_to: Date.today.year
  }
&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;def create
  person = Person.create!(person_params)
  render json: person, status: :created
rescue ActiveRecord::RecordInvalid =&amp;gt; invalid
  render json: { errors: invalid.record.errors.full_messages }, status: :unprocessable_entity
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Database activity triggers validation. An Active Record model instantiated with #new will not be validated, because no attempt to write to the database was made. Validations won't run unless you call a method that actually hits the DB, like #save.&lt;/p&gt;

&lt;p&gt;The only way to trigger validation without touching the database is to call the #valid? method.&lt;/p&gt;

&lt;p&gt;Custom Validation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person
  validate :must_have_flatiron_email

  def must_have_flatiron_email
    unless email.match?(/flatironschool.com/)
      errors.add(:email, "We're only allowed to have people who work for the company in the database!")
    end
  end
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;validate :clickbait?

  CLICKBAIT_PATTERNS = [
    /Won't Believe/i,
    /Secret/i,
    /Top \d/i,
    /Guess/i
  ]

  def clickbait?
    if CLICKBAIT_PATTERNS.none? { |pat| pat.match title }
      errors.add(:title, "must be clickbait")
    end
  end

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

&lt;/div&gt;



&lt;p&gt;We can clean up this controller action by handling the ActiveRecord::RecordInvalid exception class along with create! or update!:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create
  bird = Bird.create!(bird_params)
  render json: bird, status: :created
rescue ActiveRecord::RecordInvalid =&amp;gt; invalid
  render json: { errors: invalid.record.errors }, status: :unprocessable_entity
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the rescue block, the invalid variable is an instance of the exception itself. From that invalid variable, we can access the actual Active Record instance with the record method, where we can retrieve its errors.&lt;/p&gt;

&lt;p&gt;def render_not_found_response(exception)&lt;br&gt;
    render json: { error: "#{exception.model} not found" }, status: :not_found&lt;br&gt;
  end&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Representational State Transfer (REST)</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Tue, 11 Oct 2022 21:21:37 +0000</pubDate>
      <link>https://dev.to/arbarrington/representational-state-transfer-rest-1ah6</link>
      <guid>https://dev.to/arbarrington/representational-state-transfer-rest-1ah6</guid>
      <description>&lt;p&gt;Architectural style created by Roy Fielding&lt;/p&gt;

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

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

&lt;p&gt;You can disable the wrap parameters feature in an individual controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class BirdsController &amp;lt; ApplicationController
  wrap_parameters format: []
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also disable it for all controllers if you like, by going into the config/initializers/wrap_parameters.rb file and updating it like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
ActiveSupport.on_load(:action_controller) do
  wrap_parameters format: []
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Rails Routing</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Tue, 11 Oct 2022 17:33:16 +0000</pubDate>
      <link>https://dev.to/arbarrington/rails-routing-3059</link>
      <guid>https://dev.to/arbarrington/rails-routing-3059</guid>
      <description>&lt;p&gt;Routes&lt;br&gt;
Params&lt;br&gt;
Any time Rails receives a request with a Content-Type of application/json, it will automatically load the request body into the params hash&lt;br&gt;
to avoid mass assignmemt, use strong params:&lt;br&gt;
params.permit(:attribute1, :attribute2...)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get '/cheeses/:id', to: 'cheeses#show'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CheesesController&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def show 
    byebug
    cheese = Cheese.find_by(id: params[:id])
    render json:cheese
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The routes.rb file takes in the request to localhost:3000/cheeses/3 and processes it like normal, except this time it also parses the 3 as a URL parameter and passes it to the CheesesController.&lt;/p&gt;

&lt;p&gt;From that point, the controller action that you write will parse the 3 parameter and run a query on the Cheese model.&lt;/p&gt;

&lt;p&gt;Once we have the correct Cheese instance, we can render a JSON response.&lt;/p&gt;

&lt;p&gt;render&lt;br&gt;
By specifically defining what data is being sent via a Rails controller, we have full control over what data our frontend has access to.&lt;br&gt;
Except &amp;amp; Only&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  def index
    cheeses = Cheese.all
    render json: cheeses, except: [:created_at, :updated_at]
  end

  # GET /cheeses/:id
  def show
    cheese = Cheese.find_by(id: params[:id])
    render json: cheese, only: [:id, :name, :price, :is_best_seller]
  end`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;methods&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; render json: cheese, except: [:created_at, :updated_at], methods: [:summary]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;conditionally rendering custom error messages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if cheese
    render json: cheese, except: [:created_at, :updated_at], methods: [:summary]
  else
    render json: { error: 'Cheese not found' }, status: :not_found
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;rails routes [| grep] object-name- review routes for specific object&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources :pets, only: [:index, :show]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;status - including this in your render will not change the json response but will provide additional information for the client. Examples include "ok, not_found"&lt;br&gt;
&lt;a href="http://www.railsstatuscodes.com/"&gt;Status Codes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Postman and byebug&lt;br&gt;
In the byebug session, we can access the entire request object by using the request method:&lt;/p&gt;

&lt;p&gt;(byebug) request&lt;/p&gt;

&lt;h1&gt;
  
  
  
&lt;/h1&gt;

&lt;p&gt;This request object has all kinds of info about what was sent in the request. Try some of these methods out in your byebug session:&lt;/p&gt;

&lt;p&gt;request.request_method&lt;br&gt;
request.headers["Content-Type"]&lt;br&gt;
request.body.read&lt;br&gt;
The last one, request.body.read, will read the body of the request as a string. Nice! We could take it a step further, and parse that string as json:&lt;/p&gt;

&lt;p&gt;(byebug) JSON.parse(request.body.read)&lt;br&gt;
{"name"=&amp;gt;"Monk Parakeet", "species"=&amp;gt;"Myiopsitta monachus"}&lt;/p&gt;

&lt;p&gt;render json: movie, serializer: MovieSummarySerializer&lt;br&gt;
 render json: movies, each_serializer: MovieSummarySerializer&lt;/p&gt;

&lt;p&gt;class BirdsController &amp;lt; ApplicationController&lt;br&gt;
  rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_response&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Rails CLI Generation</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Mon, 10 Oct 2022 19:16:38 +0000</pubDate>
      <link>https://dev.to/arbarrington/rails-39ep</link>
      <guid>https://dev.to/arbarrington/rails-39ep</guid>
      <description>&lt;p&gt;&lt;a href="https://guides.rubyonrails.org/command_line.html#bin-rails-generate"&gt;Rails CLI Generation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you Cassidy for the guidance below!&lt;/p&gt;

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

&lt;p&gt;rails new application-name&lt;/p&gt;

&lt;p&gt;rails g&lt;br&gt;
-model: creates model and migration&lt;br&gt;
-migration&lt;br&gt;
-controller&lt;br&gt;
-scaffold&lt;br&gt;
-serializer: use singular for corresponding model. Dictates what attributes and json structure that will be returned&lt;br&gt;
ActiveModel::Serializer provides some powerful yet simple-to-use tools for crafting the JSON our app returns, and it does so in a way that's consistent with Rails conventions.&lt;br&gt;
To customize the JSON returned for a resource, create a serializer for that resource and list the desired attributes.&lt;br&gt;
The serializer is used implicitly by Rails based on naming conventions; to override this, custom serializers can be passed explicitly.&lt;br&gt;
AMS enables the use of the belongs_to and has_many macros in serializers to render associated data; these macros should be used sparingly.&lt;br&gt;
By default, AMS will only nest associations one level deep in the serialized JSON. To override this, the include option can be used.&lt;br&gt;
-resource: creates model, migration, controller and view files. Schema is updated/created. Controller will automatically generate 7 routes that follow REST. &lt;/p&gt;

&lt;p&gt;rails d (destroy)&lt;/p&gt;

&lt;p&gt;rails s (server)&lt;/p&gt;

&lt;p&gt;rails db (similar to rake db commands)&lt;/p&gt;

&lt;p&gt;rails c (console)&lt;/p&gt;

&lt;p&gt;options&lt;br&gt;
--no-test-framework&lt;/p&gt;

&lt;p&gt;Nomenclature for models, controllers, and views&lt;br&gt;
-Model names are always singular, and controller names are plural&lt;/p&gt;

&lt;p&gt;class-name:belongs_to&lt;br&gt;
updates association in model, &lt;br&gt;
updates schema to&lt;br&gt;
t.belongs_to :class-name, null: false, foreign_key: true&lt;/p&gt;

&lt;p&gt;rails routes&lt;br&gt;
A client sends a request to the server (this could be: a user entering a URL in a browser; a JavaScript application using fetch; etc)&lt;br&gt;
That request is sent to the server where the application's router interprets the request and sends a message to the controller mapped to that route&lt;br&gt;
The controller uses the model to access data from the database&lt;br&gt;
The controller then uses that data to render a view (HTML or JSON)&lt;br&gt;
The server returns an HTTP response, which contains the HTML or JSON data&lt;/p&gt;

&lt;p&gt;Update a migration &lt;br&gt;
-add a column&lt;br&gt;
rails generate migration add_column-name_to_table-name(s) column-name:data-type&lt;br&gt;
--api&lt;br&gt;
--minimal&lt;/p&gt;

&lt;p&gt;***Combine these command templates&lt;br&gt;
 npx create-react-app client --use-npm&lt;br&gt;
 rails new dvd-shop --api --minimal&lt;br&gt;
rails g resource Movie title year:integer length:integer director description poster_url category discount:boolean female_director:boolean --no-test-framework&lt;/p&gt;

&lt;p&gt;Adding foreign keys to join table using CLI&lt;br&gt;
rails g migration AddTaxiToRides taxi:references&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React.js</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Wed, 21 Sep 2022 17:00:02 +0000</pubDate>
      <link>https://dev.to/arbarrington/javascript-23bo</link>
      <guid>https://dev.to/arbarrington/javascript-23bo</guid>
      <description>&lt;p&gt;this - description&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Dog {
  showingThis() {
    console.log(this);
  }
}

const fido = new Dog();
fido.showingThis();
// =&amp;gt; Dog {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;scope&lt;br&gt;
fetch&lt;br&gt;
-response (r)&lt;br&gt;
--.ok&lt;br&gt;
--.json()&lt;/p&gt;

&lt;p&gt;[if res not ok] - setErrors(Object.entries(e.error).flat()&lt;/p&gt;

&lt;p&gt;Events and Event Listeners&lt;br&gt;
Looping&lt;br&gt;
JSX&lt;/p&gt;

&lt;p&gt;useEffect - triggers code to be run once component mounts&lt;br&gt;
useState&lt;br&gt;
useNavigate&lt;br&gt;
useParams&lt;/p&gt;

&lt;p&gt;We can simplify this process of making requests to the correct port by using create-react-app in development to proxy the requests to our APILinks to an external site.. This will let us write our network requests like this:&lt;/p&gt;

&lt;p&gt;fetch("/movies");&lt;br&gt;
// instead of fetch("&lt;a href="http://localhost:3000/movies%22" rel="noopener noreferrer"&gt;http://localhost:3000/movies"&lt;/a&gt;)&lt;br&gt;
To set up this proxy feature, open the package.json file in the client directory and add this line at the top level of the JSON object:&lt;/p&gt;

&lt;p&gt;"proxy": "&lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;"&lt;br&gt;
Let's also update the "start" script in the the package.json file to specify a different port to run our React app in development:&lt;/p&gt;

&lt;p&gt;"scripts": {&lt;br&gt;
  "start": "PORT=4000 react-scripts start"&lt;br&gt;
}&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8x4ilhcgtlo7xduknvxm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8x4ilhcgtlo7xduknvxm.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;async function handleSubmit(e) {&lt;br&gt;
  e.preventDefault();&lt;br&gt;
  // fetch returns a Promise, we must await it&lt;br&gt;
  const response = await fetch("/movies", {&lt;br&gt;
    method: "POST",&lt;br&gt;
    headers: {&lt;br&gt;
      "Content-Type": "application/json",&lt;br&gt;
    },&lt;br&gt;
    body: JSON.stringify(formData),&lt;br&gt;
  });&lt;br&gt;
  // response.json() returns a Promise, we must await it&lt;br&gt;
  const data = await response.json();&lt;br&gt;
  if (response.ok) {&lt;br&gt;
    console.log("Movie created:", data);&lt;br&gt;
  } else {&lt;br&gt;
    setErrors(data.errors);&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Projects/GitHub</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Mon, 19 Sep 2022 21:22:37 +0000</pubDate>
      <link>https://dev.to/arbarrington/projectsgithub-5b2g</link>
      <guid>https://dev.to/arbarrington/projectsgithub-5b2g</guid>
      <description>&lt;p&gt;Best practices for collaborating with a group&lt;br&gt;
-communication is key&lt;br&gt;
-branching, pushing, and merging&lt;br&gt;
-80% planning, 20% coding&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://whimsical.com/phase-3-brainstorming-BM5ooc1X74pNLtxmnZA52i@2bsEvpTYSt1HjGi1reMKufMh9aaSgohub2N"&gt;https://whimsical.com/phase-3-brainstorming-BM5ooc1X74pNLtxmnZA52i@2bsEvpTYSt1HjGi1reMKufMh9aaSgohub2N&lt;/a&gt;&lt;/p&gt;

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

</description>
    </item>
    <item>
      <title>GitHub Lessons Learned</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Mon, 19 Sep 2022 19:39:35 +0000</pubDate>
      <link>https://dev.to/arbarrington/github-teamwork-gcg</link>
      <guid>https://dev.to/arbarrington/github-teamwork-gcg</guid>
      <description>&lt;p&gt;Understanding branches&lt;br&gt;
Commands&lt;br&gt;
Variable naming and task delineation&lt;br&gt;
&lt;a href="https://education.github.com/git-cheat-sheet-education.pdf"&gt;Git Hub Commands&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;open a repository and change github.com to github.dev&lt;/p&gt;

&lt;p&gt;strategy: open a new branch for each feature. Git add frequently, and git commit after each success. 'git push origin branch-name'. Assign someone in the group to be the merge master. Overcommunicate about what you are working on. Proactively share component/variable names to prepare for interaction.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Ruby</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Mon, 19 Sep 2022 19:38:58 +0000</pubDate>
      <link>https://dev.to/arbarrington/ruby-106l</link>
      <guid>https://dev.to/arbarrington/ruby-106l</guid>
      <description>&lt;p&gt;Gems&lt;br&gt;
Rack - wraps HTTP requests to simplify the Application Programming Interface for servers, frameworks, and software&lt;br&gt;
-Sinatra - Domain Specific Language for creating Ruby web applications, built on top of Rack&lt;br&gt;
-CORS&lt;br&gt;
-Rake&lt;br&gt;
--Seeding&lt;br&gt;
--Migration&lt;br&gt;
-Foreman&lt;br&gt;
 gem install foreman&lt;br&gt;
Foreman works with a special kind of file known as a Procfile, which lists different processes to run for our application. Some hosting services, such as Heroku, use a Procfile to run applications, so by using a Procfile in development as well, we'll simplify the deploying process later.&lt;/p&gt;

&lt;p&gt;In the root directory, create a file Procfile.dev and add this code:&lt;/p&gt;

&lt;p&gt;web: PORT=4000 npm start --prefix client&lt;br&gt;
api: PORT=3000 rails s&lt;br&gt;
Then, run it with Foreman:&lt;/p&gt;

&lt;p&gt;foreman start -f Procfile.dev&lt;br&gt;
This will start both React and Rails on separate ports, just like before; but now we can run both with one command!&lt;/p&gt;

&lt;p&gt;There is one big caveat to this approach: by running our client and server in the same terminal, it can be more challenging to read through the server logs and debug our code. Furthermore, byebug will not work. If you're doing a lot of debugging in the terminal, you should run the client and server separately to get a cleaner terminal output and allow terminal-based debugging with byebug.&lt;/p&gt;

&lt;p&gt;You can run each application separately by opening two terminal windows and running each of these commands in a separate window:&lt;/p&gt;

&lt;p&gt;npm start --prefix client&lt;br&gt;
 rails s&lt;/p&gt;

&lt;p&gt;Active Record&lt;br&gt;
-Associations: One to Many vs Many to Many&lt;br&gt;
--timestamps and the schema&lt;br&gt;
The has_many association reference also lets you provide additional optionsLinks to an external site. to customize its behavior. In our case (and in many cases involving a one-to-many relationship), we can use the dependent: :destroyLinks to an external site. option. This will tell Active Record to delete all the associated records when the parent record is deleted&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# foreign_key: true establishes a relationship between a review and a dog house
t.belongs_to :dog_house, null: false, foreign_key: true
has_many :reviews, dependent: :destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SQL&lt;br&gt;
Database interaction&lt;/p&gt;

&lt;p&gt;Self&lt;br&gt;
"Require" - require relative, require all&lt;br&gt;
"pry" - debugging&lt;br&gt;
"colorize" &lt;br&gt;
Symbols&lt;br&gt;
Classes&lt;br&gt;
Instances&lt;br&gt;
Object Oriented Programming&lt;br&gt;
Benefits and Purposes as a Language&lt;br&gt;
-alternatives&lt;br&gt;
attr_accessor&lt;br&gt;
Class::Class-Constant&lt;br&gt;
Object Inheritance&lt;br&gt;
super&lt;br&gt;
Metaprogramming&lt;/p&gt;

&lt;p&gt;t.timestamps =&amp;gt; created_at, updated_at&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User
  def initialize(attributes)
    attributes.each do |key, value|
      # create a getter and setter by calling the attr_accessor method
      self.class.attr_accessor(key)
      self.send("#{key}=", value)
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Methods&lt;br&gt;
.order&lt;br&gt;
.pluck&lt;br&gt;
.includes?&lt;br&gt;
.any?&lt;br&gt;
.uniq&lt;br&gt;
.send&lt;br&gt;
.gsub&lt;br&gt;
.detect&lt;br&gt;
.tally&lt;br&gt;
.to_f&lt;br&gt;
.to_i&lt;br&gt;
.split&lt;br&gt;
.strip&lt;br&gt;
.compact&lt;br&gt;
.push&lt;br&gt;
.pop&lt;br&gt;
.shift&lt;br&gt;
.unshift&lt;br&gt;
.each&lt;br&gt;
.sort&lt;br&gt;
.map/.collect&lt;br&gt;
.select&lt;br&gt;
.filter&lt;br&gt;
.filter_by&lt;br&gt;
.max_by&lt;br&gt;
&amp;lt;&amp;lt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;lt;=&amp;gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>React Hooks and Component Libraries</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Mon, 19 Sep 2022 14:23:40 +0000</pubDate>
      <link>https://dev.to/arbarrington/react-hooks-and-libraries-58ok</link>
      <guid>https://dev.to/arbarrington/react-hooks-and-libraries-58ok</guid>
      <description>&lt;p&gt;To Add:&lt;br&gt;
style components&lt;/p&gt;

&lt;p&gt;React &lt;br&gt;
useState - declares a 'state variable' whose value can be preserved &lt;em&gt;between&lt;/em&gt; function calls.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [count, setCount] = useState()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;useEffect - call a function (side effect) after the component has rendered&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
    fetch("http://localhost:4000/leaders")
    .then((r) =&amp;gt; r.json())
    .then(setUserResults);
    },[])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React Router DOM Library&lt;br&gt;
useNavigate - navigate the broswer programmatically&lt;/p&gt;

&lt;p&gt;Supplementing {Router, Routes, Route}&lt;br&gt;
useParams - returns an object of key/value pairs of the dynamic params from the current URL that were matched by the .&lt;br&gt;
Router, Routes, Route&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSS Resources</title>
      <dc:creator>arbarrington</dc:creator>
      <pubDate>Thu, 25 Aug 2022 15:35:00 +0000</pubDate>
      <link>https://dev.to/arbarrington/css-grid-system-1hl6</link>
      <guid>https://dev.to/arbarrington/css-grid-system-1hl6</guid>
      <description>&lt;p&gt;&lt;a href="https://tailwindcss.com/"&gt;Tailwinds&lt;/a&gt; &lt;br&gt;
&lt;a href="https://tachyons.io/"&gt;Tachyons&lt;/a&gt; &lt;br&gt;
&lt;a href="https://getbootstrap.com/docs/3.4/css/"&gt;Bootstrap&lt;/a&gt; &lt;/p&gt;

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