<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kimberly Kohel-Hayes</title>
    <description>The latest articles on Forem by Kimberly Kohel-Hayes (@kak79).</description>
    <link>https://forem.com/kak79</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%2F410243%2F8912950c-219b-47d2-8a35-859645282981.jpeg</url>
      <title>Forem: Kimberly Kohel-Hayes</title>
      <link>https://forem.com/kak79</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kak79"/>
    <language>en</language>
    <item>
      <title>GOING FROM LOCAL STATE TO A REDUX STORE IN A REACT APP</title>
      <dc:creator>Kimberly Kohel-Hayes</dc:creator>
      <pubDate>Sun, 08 Aug 2021 20:25:03 +0000</pubDate>
      <link>https://forem.com/kak79/going-from-local-state-to-a-redux-store-in-a-react-app-1186</link>
      <guid>https://forem.com/kak79/going-from-local-state-to-a-redux-store-in-a-react-app-1186</guid>
      <description>&lt;p&gt;When choosing between local state and a redux store there is one main factor you want to take into account: how many components need access to the state. Just one, use local state. More than one, you might want to use redux. What is redux? Well in this post I'm going to define the basic components of redux and thunk while explaining how to change from locally defined state to using a redux store.&lt;/p&gt;

&lt;p&gt;In the following image I have a fetch set up as local state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7eV7-RH1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ps1qrmmfi00z7puzbhjv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7eV7-RH1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ps1qrmmfi00z7puzbhjv.png" alt="local state"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Redux is a JavaScript library that stores all of our data in a global state so that we can access it from across all components in our application.&lt;/p&gt;

&lt;p&gt;In order to use Redux you need to run either&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx install redux&lt;br&gt;
npx install react-redux&lt;br&gt;
npx install thunk&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn install redux&lt;br&gt;
yarn install react-redux&lt;br&gt;
yarn install thunk&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;in your terminal.&lt;/p&gt;

&lt;p&gt;NOTE: The redux library is not exclusive to react - it can be used with other JS frameworks.&lt;/p&gt;

&lt;p&gt;Next you need to set up your &lt;code&gt;index.js&lt;/code&gt; file like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EWRdMPQl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3820gn8vhr0rr6rxzdfs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EWRdMPQl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3820gn8vhr0rr6rxzdfs.png" alt="index.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You are importing a provider, reducer, createStore, thunk and middleware. Then you are making a store with middleware using thunk and line 13 allows use of window's devtools. Lines 18 and 22 are wrapped around App which makes it so that redux is used for state. Our provider on line 18 is for connecting our react app to our redux store.&lt;/p&gt;

&lt;p&gt;The redux store is an object that stores the global state in our app.&lt;/p&gt;

&lt;p&gt;Next you want to make a redux folder in your src folder in which to store all of your redux files. Inside the redux folder you want to add an actions folder and a reducers folder and make a reducers file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DBI64vN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cafpkas9zpxj7ylsvjkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DBI64vN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cafpkas9zpxj7ylsvjkg.png" alt="file structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O0JzQrSu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tihc17h1uz0pa8ypxi5a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O0JzQrSu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tihc17h1uz0pa8ypxi5a.png" alt="reducer.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A reducer is just a function that returns state. I am using a combined reducer here. It turns out that redux lets us combine multiple reducers into one that can be passed into createStore by using a helper function named combineReducers. This way I can put more than one reducer in my &lt;code&gt;blogReducer.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rtSySxvi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t6yp555oivs4xk84d1rk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rtSySxvi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t6yp555oivs4xk84d1rk.png" alt="reducers/blogReducer.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Examining the file &lt;code&gt;reducer/blogReducer.js&lt;/code&gt; will gain the information that the state is set to an empty array and there is something called an &lt;code&gt;action.type&lt;/code&gt; and an &lt;code&gt;action.payload&lt;/code&gt;. An action is a JavaScript object that can be an asynchronous function. Redux documentation states that 'you can think of an action as an event that describes something that happened in the application.' An action has a type and a payload. &lt;code&gt;Action.type&lt;/code&gt; is a string and should be all caps. &lt;code&gt;Action.payload&lt;/code&gt; will be other fields with additional information in them.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const add1Action = { type: 'ADD_ONE', payload: + 1 }&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C9mzXSN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sj4zf2uimiuijik9gfcv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C9mzXSN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sj4zf2uimiuijik9gfcv.png" alt="thunk"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Due to the asynchronous nature of react, if your action is a function, then you need thunk. Thunk allows asynchronous functions to return a dispatch action in the form of a function (line 3 and 4 in above image). Otherwise it returns an action object.&lt;/p&gt;

&lt;p&gt;If you follow the logic in the image below, first the &lt;code&gt;componentDidMount()&lt;/code&gt; fires which you can see because of &lt;code&gt;console.log('A')&lt;/code&gt;. Then &lt;code&gt;fetchBlogs()&lt;/code&gt; fires which you can see because of &lt;code&gt;console.log('B')&lt;/code&gt;. Then &lt;code&gt;console.log('C')&lt;/code&gt; fires before &lt;code&gt;console.log('D')&lt;/code&gt; does. This is because &lt;code&gt;console.log('D')&lt;/code&gt; cannot fire until the 2nd promise is returned in the fetch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AU0u8xSt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkl6avu0ewg4bo9htl9x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AU0u8xSt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkl6avu0ewg4bo9htl9x.png" alt="asynchronous nature of action/fetchBlogs.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to connect our components to the store, we need to import connect and use &lt;code&gt;mapStateToProps&lt;/code&gt; and &lt;code&gt;mapDispatchToProps&lt;/code&gt;. Destructuring is the process of breaking a structure. In the context of programming, the structures are the data structures, and destructuring these data structures means unpacking individual values from the data structure. On the left side, in &lt;code&gt;BlogContainer.js&lt;/code&gt;, the connect statement has &lt;code&gt;mapStateToProps&lt;/code&gt; and &lt;code&gt;mapDispatchToProps&lt;/code&gt; destructured. They are in a longer format on the right side to show the other way they can be called.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3QJezJUt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zhlj8nbodg05hpznlck7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3QJezJUt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zhlj8nbodg05hpznlck7.png" alt="mapStateToProps and mapDispatchToProps destructured"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I defined the major terms associated with redux and explained the basics about how to set up a redux store. Obviously the time when you want redux is in a significantly larger app than this, but this gives the basic idea. Good luck and happy coding.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>codenewbie</category>
      <category>react</category>
      <category>redux</category>
    </item>
    <item>
      <title>Creating a Single Page React Application with a Rails Back-End</title>
      <dc:creator>Kimberly Kohel-Hayes</dc:creator>
      <pubDate>Sun, 08 Aug 2021 19:49:52 +0000</pubDate>
      <link>https://forem.com/kak79/creating-a-single-page-react-application-with-a-rails-back-end-1o9a</link>
      <guid>https://forem.com/kak79/creating-a-single-page-react-application-with-a-rails-back-end-1o9a</guid>
      <description>&lt;p&gt;Start by making a directory with a descriptive name for your application or website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BWTMCnLl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpl277ne9j17dscamemw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BWTMCnLl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpl277ne9j17dscamemw.png" alt="terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Type the following in your terminal to initialize your backend if you are using rails as an api. The ‘-T’ means no testing and the ‘—api’ changes it from a full rails application to an api.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3lwxEPyl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7e37qzbgec1ln57q5sd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3lwxEPyl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7e37qzbgec1ln57q5sd.png" alt="terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change directory into your backend.  Do a git add and commit and open your editor.  Open your gemfile and add cors and your serializer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xuU6FScp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wotjbpgqs5t4pm9mh3wp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xuU6FScp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wotjbpgqs5t4pm9mh3wp.png" alt="terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eXIkd3z_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oxikxvvow4chklesheej.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eXIkd3z_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oxikxvvow4chklesheej.png" alt="gemfile"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to config/initializers/cors.rb and uncomment lines 8 – 16.  Change origins type to ‘*’.  In your terminal do a git add and commit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nMo9z3YG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7061t1kecogacpol9hrw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nMo9z3YG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7061t1kecogacpol9hrw.png" alt="cors file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change directory up one to your application directory.  Type the following into your terminal to initialize your frontend.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pYbiW74r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/erwa9ncz3srl9b8s3m1d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pYbiW74r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/erwa9ncz3srl9b8s3m1d.png" alt="terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D1v6DWTH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2cnem7y1vevvkinsg72.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D1v6DWTH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2cnem7y1vevvkinsg72.png" alt="terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last thing you need to do is make two remote git repositories for your frontend and backend.  Go to your git repository page and click ‘new’. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5ea9u6lq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cg5lb0czmagvstaob8dq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5ea9u6lq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cg5lb0czmagvstaob8dq.png" alt="new repo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You don’t want to use a template.  The name should be the same as the name of your frontend. If it is open source, make it public.  Click ‘Create Repository’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7dgolr6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xsv162ogtumnrb3jbibd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7dgolr6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xsv162ogtumnrb3jbibd.png" alt="new repo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a directory with a git repository already created, so you want to use that option.  Copy that code and go to your terminal.  Paste it on the command line in your terminal and hit enter.  &lt;/p&gt;

&lt;p&gt;Repeat the previous two steps for your backend.&lt;/p&gt;

&lt;p&gt;You are now ready to create a single page react app or website.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>codenewbie</category>
      <category>react</category>
      <category>rails</category>
    </item>
    <item>
      <title>MAKING A CLASS LEVEL ACTIVERECORD CHAINABLE SCOPE METHOD</title>
      <dc:creator>Kimberly Kohel-Hayes</dc:creator>
      <pubDate>Fri, 06 Aug 2021 15:05:54 +0000</pubDate>
      <link>https://forem.com/kak79/making-a-class-level-activerecord-chainable-scope-method-5cna</link>
      <guid>https://forem.com/kak79/making-a-class-level-activerecord-chainable-scope-method-5cna</guid>
      <description>&lt;p&gt;This is how to make a class level ActiveRecord chainable scope method from what is a scope to implementation.&lt;/p&gt;

&lt;p&gt;First, I had to find a good definition of scope method. I found one &lt;a href="https://medium.com/@pojotorshemi/ruby-on-rails-named-scope-and-default-scope-74ee3db2a15f#:~:text=In%20Ruby%20on%20Rails%2C%20named,to%20query%20Active%20Record%20database.&amp;amp;text=Like%20Ruby%20class%20methods%2C%20to,it%20on%20the%20class%20object"&gt;here&lt;/a&gt;. Ok. This definition brought up another thing that I don’t understand, lambdas, so let’s find a good article about those. &lt;a href="https://blog.appsignal.com/2018/09/04/ruby-magic-closures-in-ruby-blocks-procs-and-lambdas.html"&gt;This blog&lt;/a&gt; explains how to get from a method to a proc to a lambda. Great! Now we’re in business!&lt;/p&gt;

&lt;p&gt;The next thing I’m going to do is look at my models for a validation that I can call either Model.order or Model.where on. For more information on these two ActiveRecord queries go &lt;a href="https://guides.rubyonrails.org/active_record_querying.html"&gt;here&lt;/a&gt;. Fortunately, I have a year table in my Car model that I can order either ascending or descending to get the oldest or the newest car in my database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--67Uthb08--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmk9nnrwntu1db66dl2x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--67Uthb08--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmk9nnrwntu1db66dl2x.png" alt="Car Scope"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now how do I use this and chain it?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YOYAP4On--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9alz69fqa5lj0phvr8eb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YOYAP4On--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9alz69fqa5lj0phvr8eb.png" alt="Car Scope"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, I used the scope in one of my views. I then used interpolation to call on Car.oldest_car in order to access the year, make, model, the path for the link_to, and another class for the owner name. These are the results of my scope methods...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JkU4ITgD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mv2k1nhxystvltchlwmn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JkU4ITgD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mv2k1nhxystvltchlwmn.png" alt="Car Scope"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>rails</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Dropdown with Dynamic Array as Objects</title>
      <dc:creator>Kimberly Kohel-Hayes</dc:creator>
      <pubDate>Wed, 05 May 2021 18:12:19 +0000</pubDate>
      <link>https://forem.com/kak79/dropdown-with-dynamic-array-as-objects-8i1</link>
      <guid>https://forem.com/kak79/dropdown-with-dynamic-array-as-objects-8i1</guid>
      <description>&lt;p&gt;I just made a single page JavaScript application using a Rails Api for the backend.  One of the things that I had to do in the process making this application was to make a dropdown that utilized the array holding my recipes. the dropdown needed to update a the array did.  Here is how I did it.&lt;/p&gt;

&lt;p&gt;First I made the html for the base part of the dropdown.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gUE3Lblp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41fff6ctjfc3iz4uf0g8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gUE3Lblp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41fff6ctjfc3iz4uf0g8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then I made a static method in my &lt;code&gt;Recipe&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;As usual I built the method in my console using a combination of &lt;code&gt;debugger&lt;/code&gt; and &lt;code&gt;console.log()&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;So first you put a debugger in the new method before you write anything. Refresh your &lt;code&gt;index.html&lt;/code&gt;.  Figure out how to access the &lt;code&gt;&amp;lt;select&amp;gt;&amp;lt;/select&amp;gt;&lt;/code&gt; object.  In this case, as you can see from the first image, I gave it an ID of &lt;code&gt;id="dropdownButton1"&lt;/code&gt;. So in the console I called &lt;code&gt;document.getElementById("dropdownButton1")&lt;/code&gt; just to make sure it worked.  It did so in my code I assigned it to the variable name &lt;code&gt;sel&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;I add each line of code above the debugger so that the code is tested as I go and the debugger moves down a line so I can figure out the next line in the console where I can test multiple things out. &lt;/p&gt;

&lt;p&gt;I worked out the for loop in the console next.  I needed to call the for loop on my array a variable number of times, so I used the &lt;code&gt;.length&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;I wanted each element of the array inside of an option tag so next I created an element called &lt;code&gt;"option"&lt;/code&gt; and assigned it a variable. &lt;/p&gt;

&lt;p&gt;The following code is what I ended up with.  The full code to my project is posted at the bottom.  Thank you for reading my post.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rqEyLo45--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejfyu1bomnm65bpz57ig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rqEyLo45--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ejfyu1bomnm65bpz57ig.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kak79/js_project_frontend"&gt;https://github.com/kak79/js_project_frontend&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kak79/js_project_backend"&gt;https://github.com/kak79/js_project_backend&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>rails</category>
      <category>html</category>
    </item>
    <item>
      <title>Creating A Personal Website with the Pure Framework</title>
      <dc:creator>Kimberly Kohel-Hayes</dc:creator>
      <pubDate>Mon, 31 Aug 2020 15:00:48 +0000</pubDate>
      <link>https://forem.com/kak79/creating-a-personal-website-with-the-pure-framework-1nbl</link>
      <guid>https://forem.com/kak79/creating-a-personal-website-with-the-pure-framework-1nbl</guid>
      <description>&lt;p&gt;Creating this website has been a road of trial and error for me. The last time I was actively creating websites Java Script was in its infancy. You only designed websites for laptops and desktops because that's all that they could be viewed on. What I remember of HTML has changed quite a bit and CSS and JS are pretty new to me. I researched grids, flexbox and frameworks exhaustively. I tried 3 different frameworks and my own grid before I settled on &lt;a href="https://purecss.io/"&gt;Pure&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is what the home page looked like originally:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YmekG28q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/daw5ahk0b26n6i2g3wu0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YmekG28q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/daw5ahk0b26n6i2g3wu0.png" alt="Original Home Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I couldn't scroll down, the mobile looked terrible, but this one view was pretty good. If that was all I was looking for then I was fine, unfortunately, that was not the user experience that I was going for. So I gave up on writing my own grid.&lt;/p&gt;

&lt;p&gt;Neither of the first two frameworks that I looked at gave me the flexibility that I was looking for, so I end up looking for small frameworks. That is how I found &lt;a href="https://purecss.io/"&gt;Pure&lt;/a&gt;. It's small, lightweight and easy to use. With it I was eventually able to create a mobile friendly site that utilizes a small amount of Java Script. I was able to combine two of their layouts to make my blog viewer friendly.&lt;/p&gt;

&lt;p&gt;I learned a lot of CSS in this journey. I really like &lt;a href="https://purecss.io/"&gt;Pure&lt;/a&gt;, but I'd like to be able to design my own layout next time.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>How to Make a New Program From the Terminal</title>
      <dc:creator>Kimberly Kohel-Hayes</dc:creator>
      <pubDate>Fri, 14 Aug 2020 13:34:13 +0000</pubDate>
      <link>https://forem.com/kak79/how-to-make-a-new-program-from-the-terminal-21gj</link>
      <guid>https://forem.com/kak79/how-to-make-a-new-program-from-the-terminal-21gj</guid>
      <description>&lt;p&gt;I'm a flatiron school bootcamp student. I've noticed that no one in the first and second modules seems to know how to start a new program from the terminal. So here we are. &lt;/p&gt;

&lt;p&gt;Open your terminal and type the following in the directory of your choice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir new_folder
cd new_folder
bundle init 
touch config.ru  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;code&gt;bundle init&lt;/code&gt; makes a new gem file and &lt;code&gt;touch&lt;/code&gt; makes a file&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;At this point you can open your files in your IDE and edit as you usually would.  Don't forget to run &lt;code&gt;git init&lt;/code&gt; to create a new local repository and commit often!&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>codenewbie</category>
      <category>womenintech</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Which Class? Puts it in?</title>
      <dc:creator>Kimberly Kohel-Hayes</dc:creator>
      <pubDate>Tue, 21 Jul 2020 16:27:33 +0000</pubDate>
      <link>https://forem.com/kak79/which-class-puts-it-in-4kjb</link>
      <guid>https://forem.com/kak79/which-class-puts-it-in-4kjb</guid>
      <description>&lt;p&gt;I just wrote a CLI (Command Line Interface) &lt;a href="https://github.com/kak79/CLI-PROJECT"&gt;app&lt;/a&gt;.  I do not say finished, because I'm still refactoring it. I have multiple classes in this &lt;a href="https://github.com/kak79/CLI-PROJECT"&gt;app&lt;/a&gt;.  The viewpoints on class responsibility vary. Specifically the interface class responsibility versus the methods class. Some say that you could put &lt;code&gt;puts&lt;/code&gt;, &lt;code&gt;inputs&lt;/code&gt; and &lt;code&gt;gets&lt;/code&gt; methods in whichever class you could justify them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vctMQQbm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ce13xrnvjy1na5xh18cx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vctMQQbm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ce13xrnvjy1na5xh18cx.jpg" alt="Alt Text"&gt;&lt;/a&gt; &lt;br&gt;
Others say that they need to be in the CLI class so that if I ever change the project to a web project they will all need to be in the same class and not in the methods class for ease of access.&lt;/p&gt;

&lt;p&gt;In my case we are dealing with &lt;code&gt;class CLI&lt;/code&gt; and &lt;code&gt;class Photographer&lt;/code&gt;.  Most of my &lt;code&gt;puts&lt;/code&gt;, &lt;code&gt;inputs&lt;/code&gt; and &lt;code&gt;gets&lt;/code&gt; are in &lt;a href="https://github.com/kak79/CLI-PROJECT/blob/master/lib/cli.rb"&gt;&lt;code&gt;class CLI&lt;/code&gt;&lt;/a&gt;, but having listened closely to everyone, I have decided that I need to do some refactoring of these methods in &lt;code&gt;class Photographer&lt;/code&gt; in order to move the puts to &lt;code&gt;class CLI&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--psS2GC42--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cm1b0b7bepvhah66p0l7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--psS2GC42--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cm1b0b7bepvhah66p0l7.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o0k8d6Fw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nssiaczoh0nui6hx2kma.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o0k8d6Fw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nssiaczoh0nui6hx2kma.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FJlazaBK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n6jniwqsmfl0q44b02sk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FJlazaBK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n6jniwqsmfl0q44b02sk.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First I am going to copy the two methods with the &lt;code&gt;puts&lt;/code&gt; statements whole and paste them into the &lt;code&gt;CLI class&lt;/code&gt;.  Then I have to change a few things to make them a part of class &lt;code&gt;CLI&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The first thing I do after moving pic_taker_array to &lt;code&gt;CLI&lt;/code&gt; is change it from a class method to an instance method by removing the &lt;code&gt;self.&lt;/code&gt;. I also need to change the way I call it in the &lt;code&gt;CLI&lt;/code&gt; class from &lt;code&gt;Photographer.pic_taker_array&lt;/code&gt; to &lt;code&gt;pic_taker_array&lt;/code&gt;.  Then I put a &lt;a href="https://dev.to/honeybadger/why-pry-is-one-of-the-most-important-tools-a-junior-rubyist-can-learn-2mp7"&gt;pry&lt;/a&gt; on the first line of this method so that I can see exactly how I need to modify it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--leTY3ymV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/32838mjfw9chnpjv0336.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--leTY3ymV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/32838mjfw9chnpjv0336.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NiFJL3TO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g9id3cufkgjpo1e8lqdx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NiFJL3TO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g9id3cufkgjpo1e8lqdx.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have a method in my &lt;code&gt;Photographer&lt;/code&gt; class called &lt;code&gt;self.all&lt;/code&gt; that calls &lt;code&gt;@@all&lt;/code&gt; so I'm going to try that in my &lt;code&gt;pry&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HZYT1Sip--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2qizt81i42fjpnhwnkzo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HZYT1Sip--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2qizt81i42fjpnhwnkzo.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I run the program and see that my photographers are no longer displayed properly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sFqRQ_5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m5kmwz061xq7m393hh84.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sFqRQ_5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m5kmwz061xq7m393hh84.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I need to edit the display method so that so that it will accept a photographer into the methods pic_taker, pic_taker_url, and orig_url. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hTHVPp5r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uasu5y1yhfz3u4imhopi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hTHVPp5r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uasu5y1yhfz3u4imhopi.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I try running my program again and realize that display is not getting called. This leads me to the line of the &lt;code&gt;glue&lt;/code&gt; method where &lt;code&gt;search_pic_taker_array&lt;/code&gt; is supposed to be called but is getting skipped, so I decide to take the contents of &lt;code&gt;search_pic_taker_array&lt;/code&gt; and move them to &lt;code&gt;glue&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1uV4SP_4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tqqc46xkwdxi7j31708q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1uV4SP_4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tqqc46xkwdxi7j31708q.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vIyzYKVl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4bj60980gzsjcezpnnjt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vIyzYKVl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4bj60980gzsjcezpnnjt.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I run my program and check everything. The photographers display perfectly now! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xZe0p_oz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ruf3aepz6z11jsfcxtrc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xZe0p_oz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ruf3aepz6z11jsfcxtrc.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>tutorial</category>
      <category>codenewbie</category>
      <category>refactorit</category>
    </item>
    <item>
      <title>Selecting Hashes from an API</title>
      <dc:creator>Kimberly Kohel-Hayes</dc:creator>
      <pubDate>Thu, 16 Jul 2020 18:17:45 +0000</pubDate>
      <link>https://forem.com/kak79/selecting-hashes-from-an-api-989</link>
      <guid>https://forem.com/kak79/selecting-hashes-from-an-api-989</guid>
      <description>&lt;p&gt;Selecting hashes from an API can seem like a very complicated process, so let's take it one step at a time. We will be storing everything in variables for ease of access. The definition to a variable can be found &lt;a href="https://en.wikipedia.org/wiki/Variable_(computer_science)"&gt;here&lt;/a&gt;. &lt;br&gt;
The first thing we are going to do is set our API equal to a variable named response. Then we are going to put in a pry (see more about pry &lt;a href="https://github.com/pry/pry"&gt;here&lt;/a&gt;) and look at our available hash.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zc4g97xC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lhp9ufgotnxlksbiggug.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zc4g97xC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lhp9ufgotnxlksbiggug.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
We want to select a key from response that has multiple keys as it's value.  If we look closely, &lt;code&gt;'page'=&amp;gt;1,'per_page'=&amp;gt;1&lt;/code&gt; so they each have individual returns and &lt;code&gt;'photos'=&amp;gt;[{&lt;/code&gt; which means not only does it have an array, it has an array of hashes. &lt;br&gt;
We are going to save &lt;code&gt;'photos'&lt;/code&gt; into the variable photos_array like this and run the pry again to select our next key. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nh-OcqBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x28dasapzo6vzvjpjdwy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nh-OcqBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x28dasapzo6vzvjpjdwy.jpg" alt="Alt Text"&gt;&lt;/a&gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p3P5ukhC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f1zc0h5s71klniwif6lh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p3P5ukhC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f1zc0h5s71klniwif6lh.jpg" alt="Alt Text"&gt;&lt;/a&gt; &lt;br&gt;
We are going to pick three.  &lt;code&gt;'photographer', 'photographer_url', and 'src'=&amp;gt;'original'&lt;/code&gt;&lt;br&gt;
So using our &lt;code&gt;binding.pry&lt;/code&gt; we gradually develop these three lines of code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LNIYZp5m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ptaccd2evp9z39yxt9j8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LNIYZp5m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ptaccd2evp9z39yxt9j8.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
This code will work. But it isn't very DRY code. Don't Repeat Yourself! We are going to refactor this code next.&lt;br&gt;
Because we want to iterate over three things we are going to use the &lt;code&gt;.each&lt;/code&gt; method, naming our variable photographer_hash and setting up the block something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J6F3qXlU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/turfr3i7n5y3czx3fapa.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J6F3qXlU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/turfr3i7n5y3czx3fapa.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have a new Photographer object that iterates through my API and returns all of the values.  But it could still be better.  Instead of &lt;code&gt;Photographer.new....&lt;/code&gt;, we are going to set up a new variable called info_hash.  Set it equal to: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PW0QcHyG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y9fkcd3m75ye52pa1dgh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PW0QcHyG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y9fkcd3m75ye52pa1dgh.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The reasons behind the locally defined keys &lt;code&gt;pic_taker, pic_taker_url,&lt;/code&gt; and &lt;code&gt;orig_url&lt;/code&gt; have more to do with OOP and classes than APIs and refactoring so will not be gone into here.  Just understand that they were defined in another class.  The last thing to do here is to put &lt;code&gt;Photographer.new&lt;/code&gt; back in with its new argument of &lt;code&gt;info_hash&lt;/code&gt; with the resulting API looking like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HXbBwgNk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n2qufizskds7pqw63cp7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HXbBwgNk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n2qufizskds7pqw63cp7.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All of the code examples in this article and their associated files can be found &lt;a href="https://github.com/kak79/CLI-PROJECT"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>codenewbie</category>
      <category>refactorit</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Creating a Custom RegEx</title>
      <dc:creator>Kimberly Kohel-Hayes</dc:creator>
      <pubDate>Mon, 29 Jun 2020 16:57:47 +0000</pubDate>
      <link>https://forem.com/kak79/creating-a-custom-regex-5hm6</link>
      <guid>https://forem.com/kak79/creating-a-custom-regex-5hm6</guid>
      <description>&lt;p&gt;Want to have a little programming fun? Let's create a RegEx! What is a RegEx? Well funny you should ask that! A RegEx or Regular Expression is a search string of condensed datum. Let's say you wanted to search for all capital letters in a given set of text. How would you go about it? A RegEx.  This post will explore creating a RegEx for few different situations.&lt;br&gt;
Before we start, three resources that will help anyone trying to build a RegEx are the following websites: &lt;br&gt;
&lt;a href="https://regexr.com/"&gt;Regexr&lt;/a&gt;&lt;br&gt;
&lt;a href="https://rubular.com/"&gt;Rubular&lt;/a&gt; &lt;br&gt;
&lt;a href="https://ruby-doc.org/core-2.6/Regexp.html#method-i-match"&gt;Ruby Docs Regexp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OO9JYMRr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kk8a2rvqwfruix5v461z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OO9JYMRr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kk8a2rvqwfruix5v461z.jpg" alt="starts_with_a_vowel"&gt;&lt;/a&gt;Lets walk through method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;starts_with_a_vowel
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and the steps I used to successfully find a working RegEx. We'll start by picking out a list of words.  Find some that are capitalized and some that are not. Pick at least one, or more that starts with each vowel, capitalize some and leave some lower-case.  Pick out a few words that start with consonants.  Throw in some punctuation.  Maybe some numbers.  Now we have our list.  Go to either &lt;a href="https://regexr.com/"&gt;Regexr&lt;/a&gt; or   &lt;a href="https://rubular.com/"&gt;Rubular&lt;/a&gt;  and enter your list in the text area. Make sure that you delete any sample text that was there already.  In the RegEx area (which you might have to delete as well) you start entering possibilities.  Play with it. Both sites give you plenty to go on.  See if you can solve it differently than I did.&lt;br&gt;
Now let's do something a little more complicated! Let's see if we can match all valid phone numbers but kick out all invalid phone numbers! You are really going to have to use your imagination and maybe do some research on this one! Here's what I came up with.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vxP2L1Ad--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i3nm1a65yc014063puas.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vxP2L1Ad--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i3nm1a65yc014063puas.jpg" alt="valid_phone_number"&gt;&lt;/a&gt;&lt;br&gt;
I hope you have some fun with this programming problem. &lt;/p&gt;

</description>
      <category>ruby</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
