<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Elaine Doud on Medium]]></title>
        <description><![CDATA[Stories by Elaine Doud on Medium]]></description>
        <link>https://medium.com/@elainedoud?source=rss-8c6a9edfc159------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fi7aqViKaDkOazCwjkx0vQ.jpeg</url>
            <title>Stories by Elaine Doud on Medium</title>
            <link>https://medium.com/@elainedoud?source=rss-8c6a9edfc159------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:28:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@elainedoud/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Recursion]]></title>
            <link>https://medium.com/@elainedoud/recursion-7eb24cba790c?source=rss-8c6a9edfc159------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eb24cba790c</guid>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Elaine Doud]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 22:02:07 GMT</pubDate>
            <atom:updated>2023-05-15T20:29:59.448Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ctXCvI4HE_xVRMNguSr4og.jpeg" /></figure><p>Summer is almost upon us and flowers are blooming! Let’s use this time to dicuss recursion. Although it can seem complicated at first, recursion occurs when a function calls itself. When set up correctly, it is a pleasing way to set-up code and may have less key strokes than other methods.</p><p>To start, we cannot discuss recursion without discussing the call stack. The call stack is the stack of called functions. As I explained in “Using A Stack in JavaScript”, a stack is a pile of items with the item on top being processed first. For the call stack, the most recent function (function at the top of the stack) will be resolved first, then the next function on the stack, ect. A recursive function will be the same function piled on top of itself with some minor changes to the input. But if the function keeps calling itself, how do we keep it from infinitely calling itself or causing an error?</p><p>A condition is used to signal the recursive function to stop calling itself and to exit the function. This is one of the most important parts of this type of function. If this is not done you will max out your call-stack and will receive an error message.</p><p>Let’s say we want to use a recursive function to show a countdown in our console. To stay on topic, let’s do a count down to summer. The first day of summer is June 21st and today is April 26th — so let’s do a countdown of 56 days. For our purposes we’ll say n is 56, and use n as our input. Since we want to start at 56, we will first console.log this using console.log(n). Then let’s call our function again, but now we want our input to be 55 or (n — 1). If we run this function without a condition it’s going to loop forever and break our program. Let’s add a condition to the first line — if (n &lt; 1) return 0, since we want our countdown to end at 0. Now when we run our function it will console.log every number from 56 through 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*_F7l4teqhNlSfcAqlVSBjw.png" /></figure><p>Let’s move onto a function a that is a bit more complicated. With a recursive function it is possible to call the same function twice with different inputs before any recursion starts. For this example let’s use the Fibonacci Sequence. The Fibonacci Sequence is a sequence of numbers where each number is the sum of the two numbers to its left. Below shows up to 34, but it is an endless sequence. It was used to develop the Golden Ratio, which is often found in nature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*OJCo1BIhJAasc3Bfa6esCg.png" /></figure><p>Our goal will be to input the position of an integer, and have the value of the integer be returned. So if we enter 1, the output should be 1. If we enter 3, the output should be 2. For 6, the output will be 8. Let’s have our input equal y.</p><p>Our condition will need to kick in if n= 2 or n= 1, because in both cases the output will be 1. Therefore, we will set our condition as if (n &lt; = 2) return 1. Then we will want to use one recursion function to determine the first number to the left of n, and a second recursive function to determine the second number to the left of n. By adding these altogether we get the n number in the placement. Below is the code, showcasing n= 9, which will result in 34.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*wBFIg-F_czp6Y5GZOlOStg.png" /></figure><p>Using creativity, recursion can be used to solve a variety of mathematical equations or data related problems.</p><p>Sources:</p><p><em>JavaScript Recursion</em>. Programiz. <a href="https://www.programiz.com/javascript/recursion">https://www.programiz.com/javascript/recursion</a></p><p><em>How Recursion Works — Explained with Flowcharts and a Video.</em> freeCodeCamp. <a href="https://www.freecodecamp.org/news/how-recursion-works-explained-with-flowcharts-and-a-video-de61f40cb7f9/">https://www.freecodecamp.org/news/how-recursion-works-explained-with-flowcharts-and-a-video-de61f40cb7f9/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eb24cba790c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Back to Basics]]></title>
            <link>https://medium.com/@elainedoud/back-to-basics-9ca97c9eafe0?source=rss-8c6a9edfc159------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ca97c9eafe0</guid>
            <category><![CDATA[methods]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Elaine Doud]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 20:18:10 GMT</pubDate>
            <atom:updated>2023-05-15T16:42:09.563Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b8k7ounAXOJ4-nNLmyvnzQ.jpeg" /></figure><p>If you’ve been on my portfolio or LinkedIn page recently, you’ve seen that I am working on a new project called “Habitat Hunt”. It’s an application to make the process of apartment hunting easier for consumers. This project is built with a Ruby on the Rails backend and React frontend. Upon trying to pull specific information for the apartment listings I got myself into a conundrum and had to go back to the basics of Ruby to get myself out of it.</p><p>The website’s back end is made up of two Ruby Models (Listing and Category) which are connected by a join table. This means that through the join table every Listing has many Categories and every Category has many Listings. Theoretically it should have been fairly easy to share information between the two using Ruby on the Rails methods.</p><p>Once the backend was set-up, data seeded, and navigation bar built out on the frontend’s App, I began attempting to parse out the information in React. My goal was to have one page called “In-Progress” which only showed Listings where the Category’s name was “In-Progress”. I was able to pull all the Listings and have them display on the page. This was great because it confirmed that my project was set-up correctly so far and that the front-end &amp; back-end were communicating effectively. However, when I tried to parse out the data by Listings where category = “In Progress” I could not figure out how to make it work. When I looked at the information being pulled, the “category_name” [which I was trying to obtain] was inside an object, inside of an array, inside an object (the Listing) inside an array of all the Listings. This would be very complicated.</p><p>I switched to another tactic and attempted to pull the Categories to parse the data. This was equally complicated. In this case the details for the Listings [which I needed now] were in an object, inside an array, inside an object (Category_Name) inside the array of Categories. I was stumped; in a previous project I had mapped over data twice to get the desired details, but I had never encountered a situation where the data was mired four levels deep.</p><p>Fed up with React, I started Googling and skimming documentation to see if Ruby might have an answer. After all, Ruby has a reputation for being easy to work with. I found exactly what I needed — the method “joins”. In Ruby “joins” allows you to combine information. By using this in my Listings Controller, I would be able to parse my information on the backend rather than in React. Using joins allowed me to combine Listings and Categories. By also including “where” I can specify which categories I want pulled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kc_SylKKXPb8iR6xiDhCKw.png" /></figure><p>Now that my inprogress method was clearly defined, I needed to create a specific route for it so I could get it to the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*BKashehv2rJrp43zJgByew.png" /></figure><p>I then switched to working on my App on my frontend. Using React, I pulled the “/inprogress” data via useEffect( ) and fed it down to the In Progress component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*ixZcnyupPgvkafekIPcgWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8UIF4OX2XHO_wk3ZE0eB3Q.png" /></figure><p>On the In Progress component itself I was able to easily divide the information by its separate labels, like apartment name and address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X6i7vbkR4h8jDCD8o7Buww.png" /></figure><p>By going back to the basics of Ruby I was able to find a sleek solution that not only worked but was also straightforward to set-up. This has inspired me to continue learning more about Ruby as I build this project. Who knows what other exciting methods I will find?!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AZNvt76ERBOlM7RkMFkz3Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ca97c9eafe0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using A Stack in JavaScript]]></title>
            <link>https://medium.com/@elainedoud/using-stack-in-javascript-d85c97231c6c?source=rss-8c6a9edfc159------2</link>
            <guid isPermaLink="false">https://medium.com/p/d85c97231c6c</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[stack]]></category>
            <dc:creator><![CDATA[Elaine Doud]]></dc:creator>
            <pubDate>Fri, 10 Mar 2023 21:37:29 GMT</pubDate>
            <atom:updated>2023-03-10T21:41:06.475Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wa4IBcfLWNKLDheRoPuRnQ.jpeg" /></figure><p>Stack is a Data Structure that works on a basis of Last In, First Out. They give you easy access to the most recent addition to the data structure. Common metaphors to describe Stack are a pile of dishes or a pile of bills. You use the dish on top first, and do not have access to the dish at the bottom [or first added to the stack] until all the other dishes have been removed. Or think of passengers on a full, express train — the last passenger on the train will be the first one to disembark. A Stack is commonly used for functions like the back button on a website or an undo button, since only one layer of information is needed at a time.</p><p>The methods to use a Stack are straightforward and often involve the top item in a stack. To add a value to the top of the stack, the syntax is push( ), whereas pop ( ) is the syntax to remove the top value from the stack. If you just want to determine what the top value of a stack is, you can use peek( ).</p><p>To determine how many items are in a stack, the method length( ) can be used. isEmpty( ) will return true if the stack is empty and will return false if it contains a value. You can also use two (or more) Stacks at a time to interact with data.</p><p>Let’s say we’re needing to track boarding groups for an amusement park ride, like Tower of Terror at Walt Disney World. If boarding groups are made up of eight people, we can use stack_1 to determine Boarding Group One.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvKnLpXoWslGOdJkj4G9kw.png" /></figure><p>We can easily make the boarding group larger or smaller by changing i &lt; 8 to either i &lt; 4 (for ride vehicles seating four) or i &lt; 10 (for ride vehicles seating ten).</p><p>We can then implement stack_2 if we want to move guests from the boarding group to the actual ride.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*aDy6x7FYsN3bsIlQtc8iSQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*hsmcox9D1D9J0_4viNkhCg.png" /></figure><p>Stacks are an easily accessible data structure to work with to keep track and organize data.</p><p>Sources:</p><p><strong>“Implementation of Stack in JavaScript” Geeks for Geeks.</strong> &lt;https://www.geeksforgeeks.org/implementation-stack-javascript/&gt;</p><p><strong>“Implementing JavaScript Stack Using an Array” JavaScript Tutorial.</strong> &lt;https://www.javascripttutorial.net/javascript-stack/&gt;</p><p><strong>“Deep Dive into Data structures using Javascript — Stack” Sahin Arslan.</strong></p><p>&lt;https://www.sahinarslan.tech/posts/deep-dive-into-data-structures-using-javascript-stack&gt;</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d85c97231c6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is Your Python Code Readable?]]></title>
            <link>https://medium.com/@elainedoud/is-your-python-code-readable-cf7ee790e1d2?source=rss-8c6a9edfc159------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf7ee790e1d2</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[style]]></category>
            <category><![CDATA[readable-code]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Elaine Doud]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 22:11:58 GMT</pubDate>
            <atom:updated>2023-03-02T22:11:58.067Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*eyobfKcrif9Qfe50WmIniw.jpeg" /></figure><p>As I embark on learning to code Python, I am paying attention to the details of how my code is written. Not just its functionality, but making sure my code sticks to best practices and can be easily interpreted by others. This is an important habit to incorporate so if a web application is created or part of a code base is written in the future, other software engineers can easily see what the code is doing and the work can be revised. I referred to the PEP 8 Style Guide for Python code to get a clearer picture of what best practice in coding Python looks like.</p><p>In Python, spaces are generally preferred over tabs. If you choose to do so, you can use code — but tabs and spaces should not be mixed! The importance of consistency will be a reoccurring theme in this blog. For humans, it is easier for us to read content and understand it if it is consistent. Identation should consist of four spaces. In the below example, print is indented 4 spaces from the beginning of the first line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*RAu9POEZo3_RCt5qnN9egw.png" /></figure><p>In Python, a line should be limited to 75 characters. If your code will surpass the 75 character limit, you can use a hanging indent to move your overflowing code to the next line and make sure it is still readable. For handing indents, the priority is lining up the overflowing code with its counterpart on the previous line so it’s easier to read. Therefore, hanging indents do not need to be indented four spaces. Below is an example of overflowing code making use of a hanging indent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aj_Q38lu05BWMqOp-_IHNw.png" /></figure><p>Extra whitespace between parenthesis and punctuation should also be avoided. I sometimes have to remind myself that I am writing code, not a term paper. Below is an egregious example of white space. In general it’s good practice to reread your code to make sure an extra space has not snuck into your code by accident.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*itxT79SHw5ec3Qia6AykHw.png" /></figure><p>Lastly, it is important that Python code contain comments and that these comments be easy to read. Python comments should be written in complete sentences and should begin with a capital letter, unless the first word is a variable that is lower-case. If there are multiple sentences in a comment, there should be two spaces after a period. (My term paper practice finally comes in handy here!). Comments are especially important if there is a section of code whose purpose is unclear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*maDFvDCBjMSYBl3cS1_XGA.png" /></figure><p>There are cases where the PEP 8 Style Guide does not have a preference. In these cases you can choose how you would like to style your code, but you should strive to always be consistent. Remember, consistency is key!</p><p>Sources:</p><p><a href="https://peps.python.org/pep-0008/">PEP 8 - Style Guide for Python Code | peps.python.org</a></p><p><em>Five Tips to Elevate the Readability of your Python Code. </em>Engineering for Data Science</p><p><a href="https://engineeringfordatascience.com/posts/top_tips_for_improving_python_code_without_refactoring/">https://engineeringfordatascience.com/posts/top_tips_for_improving_python_code_without_refactoring/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf7ee790e1d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Danger of Duplicate Table Names]]></title>
            <link>https://medium.com/@elainedoud/danger-of-duplicate-table-names-e7603a3e8455?source=rss-8c6a9edfc159------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7603a3e8455</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Elaine Doud]]></dc:creator>
            <pubDate>Mon, 13 Feb 2023 19:23:20 GMT</pubDate>
            <atom:updated>2023-02-13T19:23:20.723Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wqG2TGhyafpwQ5ddLdfOdA.png" /></figure><p>As a new software developer there is a phase where you move past being paranoid of breaking everything and start to become more comfortable. This can lead to unexpected results, since there’s still a lot you are learning. I was feeling much more comfortable with frameworks as I began working on my second Ruby on the Rails project, a banking website called Treasury National Bank. I knew how to build tables in Rails using Postgresql. I was also feeling confident because I was going to use the same template I used for my first Ruby on the Rails project. This template is going to become the crux of this saga!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*bwjUxzrQlLKA4m4icAK_Zw.png" /></figure><p>My first Ruby on the Rails project was a candy website, Kandi Apple’s Sweete Shoppe. Both of my projects had the requirement of having users be able to log into the respective websites. In the spirit of keeping things simple, I created a table on both projects called “Users”. Errors, including one that stated Users was already being used, began to pop up as soon as I tried to seed data. This seemed strange, but dropping my tables and starting over appeared to rectify the errors. I assumed I had simply made a typo with my initial migrations.</p><p>Weeks later I discovered the true error when I was checking on both rails projects on the same day. My banking website was working smoothly, so I switched over to my candy shop website — only to discover to my horror that it was not displaying any of its candy! After tinkering with the candy shop project (and reseeding the data) I was able to get it working fine. Luckily, I then switched back to the banking website to check it one last time — and discovered it had completely stopped working! Changes to one project was breaking the other like they were connected — but why?</p><p>A developer on Stack Overflow listed virtually the same conundrum. The answer they were given is that their tables were likely in a shared database. Changing the name of one of the tables would alleviate this error. I had the realization that my projects were also sharing the same database — the Postgresql database I had cloned as part of the project template. The shared names were resulting in unexpected errors, and were overwriting the data of each other. This is why “fixing” one project was breaking the other. In order to have two working projects, I needed to change one of the table of Users to a new name. However, since the backends were fully built out, I would also need to change the name within my models, controllers, serializers and routes.</p><p>I decided to refactor the candy website project and rename the Users table there, because this project was slightly less complicated than my banking website. I first created a migration to rename the table users to customers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*GcrNPpwx8afTMBTluNnKbQ.png" /></figure><p>I then went methodically through my models, routes, controllers, and serializers, and changed ever mention of “user” or “users” to “customer(s)”. This included updating my references to users in my sessions controllers, and also updating my seed file. My seed file would have to create customers, so it would not work if it was still pulling information for users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rZpVRogcn09PbJDndmczDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*kXIsXNle0NyC11hHQGYwmA.png" /></figure><p>Thankfully, after running the migrations and seeding my data, the candy website was successfully working. I also immediately checked my banking website, which was now working correctly too. I had surgically and successfully separated my two Ruby on Rails projects. It was a successful end to a significant coding challenge, but also imprinted an important lesson in my mind. It is a best practice to avoid giving tables the same name from the start — especially if there’s a small chance they might be sharing a database.</p><p>References:</p><p>Stack Overflow | Two Rails project share the same database … how to make everyone happy</p><p><a href="https://stackoverflow.com/questions/29807748/two-rails-project-share-the-same-database-how-to-make-everyone-happy">https://stackoverflow.com/questions/29807748/two-rails-project-share-the-same-database-how-to-make-everyone-happy</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7603a3e8455" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Power of Serializers]]></title>
            <link>https://medium.com/@elainedoud/power-of-serializers-686428678680?source=rss-8c6a9edfc159------2</link>
            <guid isPermaLink="false">https://medium.com/p/686428678680</guid>
            <category><![CDATA[serializers]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Elaine Doud]]></dc:creator>
            <pubDate>Sun, 08 Jan 2023 21:03:59 GMT</pubDate>
            <atom:updated>2023-01-08T21:03:59.778Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*BQHLpZ15BTsupBR3W1TelQ.jpeg" /></figure><p>My recent project using React with Rails as my backend demonstrated the power of serializers. Serializers allowed me to pull information from three separate models, and have them rendered within one React component. The project was an online marketplace for candy. My three models were Candy, User, and Review. Candy and User had a many-to-many relationship, and Review was the join table (aka through table). Firstly, I made sure each model had the appropriate relationship with each other. The join table, Review, belongs to both Candy and User. Both Candy and Users have many Reviews. Candy has many Users through Reviews, and Users has many Candies through Reviews.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*ah-o_psiNmUaBrjwM5fcdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*_mm5oTxoSIGUbD3u0a4RcA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*xb8233-TeWM7nEfjFCc82w.png" /></figure><p>Next, serializers can be set up to show the model attributes you choose. The has many and belongs to relationships will need to be reflected on the serializers as well. This is key to being able to successfully combine information from the models within React. Below is the example of the three serializers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*vKE08jvFOGGsMhwy7P1V_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*JSSu0KtX3pozYfmyp7DVuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*i3i5Pn-kNveIpChtKuFgeA.png" /></figure><p>For the project, I will want to display all of the reviews. In order to do this, it is time to make the appropriate method in the Reviews Controller and the correct route in the routes. To view (or review) items within the controller, an index method must be created. Demonstrated below, a params method was created as well to make writing out additional methods for this controller easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*Bvr0d9cORXQISnPfiYaibQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*sgy5NpJaNWLYs6oS4owiGA.png" /></figure><p>Then the route can be added to our routes.rb file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*XzaqxSy4Og5ERl_H_JKVLQ.png" /></figure><p>The controller and route will work together. Route connects the frontend to the backend. When “/review” is called on the frontend, then the index method within the Review Controller will be triggered. For the sake of this example, let’s say we already seeded our data. For the time being we’re done with the backend. Now we can move to the frontend.</p><p>In order to display the reviews it makes sense within React to build a parent component, which we can call Reviews, with a child component, which we can call ReviewCard. On our Reviews component we will want to set our state, fetch “/review” to obtain our data, and then map over our data (which is in this case our reviews).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*Xe9Pz5AQ8yPD4QboLx2Vuw.png" /></figure><p>We will then be passing {review} down to our ReviewCard as a prop. Below is the example of the ReviewCard component. We will then review it — particularly the portions that are pulling information from our Candy and User models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QipRqItr1bXmh8seqLj6dA.png" /></figure><p>The comment for each review is on the Review model, so this is the easiest to obtain by putting {review.comment}. Luckily, the attributes for the respective candies and users are only one layer away. This is because candy_id and user_id are both on our Review Model since it is the join table. The attributes at our disposal are what we placed in our serializers, which can be seen at the top of the blog. To show the name of the candy being reviewed we type out {review.candy.name}. To show the username associated with the review we type {review.user.username}. Within our ReviewCard component, since we connected our models and serializers, we can show not only the review comment — which is directly in our Review model, but also it’s associated candy and username. It is our serializers that made this possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=686428678680" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby Methods and Active Record]]></title>
            <link>https://medium.com/@elainedoud/ruby-methods-and-active-record-fbd0c812e505?source=rss-8c6a9edfc159------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbd0c812e505</guid>
            <category><![CDATA[activerecord]]></category>
            <category><![CDATA[methods]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Elaine Doud]]></dc:creator>
            <pubDate>Sun, 11 Dec 2022 23:23:26 GMT</pubDate>
            <atom:updated>2022-12-11T23:23:26.196Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*VAPD5kaCL96FG4t1DE0LDw.jpeg" /></figure><p>Active Record makes it easier to create tables within Ruby, link these tables, and interact with the information in these tables using methods. These methods are numerous and often can be chained together. Some methods can be used in multiple ways. This combined with other aspects of Ruby (like the shorthand allowed by Ruby’s syntactic sugar) can make it difficult to understand exactly what’s occuring with a method. When I was learning Ruby I found that a lot of the reference material online used a lot of jargon and would often cover just one method. In this blog I will explain and provide detailed examples for several methods. This in no way covers everything, but hopefully this will be both easy to read and refer back to if needed.</p><p>What is Active Record? Active Record is an Object/Relational Mapping Layer. Active Record makes it much easier to create tables of data, and connect these tables so they can interact together. With Active Record you can create a table simply by typing commands into your terminal. The tables can then be linked together using one-to-one, one-to-many, or many-to-many relationships. Active Record is user-friendly because CRUD actions (Create, Read, Update, and Delete) can be performed on every Active Record by using Ruby code. These actions are referred to as methods.</p><p>The <strong>.where </strong>method is helpful because it allows you to query through your database. Let’s say you have three tables — writers, readers, and blogs. The writer can have many blogs, and many readers through the blogs. The readers can have (read) many blogs, and are linked to many writers through the blogs. The blogs table (our join table) belongs to both the writer table and the reader table. Every blog has a title, a category, and an integer for the amount of publications it has. If you wanted to create a method where a category was input and it would return all instances of that category in the blogs, that method could look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*idYsz0GSjC3CMB9kKUUYSg.png" /></figure><p>What this method is doing is iterating over the objects provided and returning any instance where its characteristic(s) match what was placed in the function’s argument. In this case the blogs (defined as self) are the objects that .where is reviewing. The method .where will return multiple instances if they match the provided criteria. It can also be used to to match multiple points of data. What if you wanted to be able to find any blogs that matched both a specific category and title? We could simply write an instance that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lhYxPJJWZ4UEwrsN_XPfBg.png" /></figure><p>If you’re expecting only one matching record, you can use <strong>.find_by</strong> instead. For example, if you’re already familiar enough with your data to know there are no duplicate titles, you might prefer to use .find_by to search for a blog using its title. This is more efficient than .where, because it will stop running as soon as it finds the match. It is important to know that the similarly worded method <strong>.find </strong>does not work the same way. The method .find will only work if you are using the object’s id as the argument.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*gzaGkrnHKPu3csl1S4QSFA.png" /></figure><p>The above methods are helpful if you are doing queries for strings or exact matches. But what if you want to find the largest value in a row or a table. To do this you can use the method <strong>.max_by. </strong>The method .max_by iterates over a specific group of characteristics, specified by a block of code, and returns the characteristic with the highest value. Here is an example of using .max_by to find the blog with the most amount of publications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FYY9u1xhZBF41dvdWXEung.png" /></figure><p>The code block is important. It tells the max_by function what we want to focus on in what we’re iterating over (in this case, to pay attention to the blogs making up the Blogs table) and then to make its comparisions to the publication of each blog. It will then return the instance with the highest number of publications. This is super handy when you data in integers that you want to compare. What if instead of calling this within the Blog table, we wanted to call this within the Writer table, and determine which writer has the most blogs. Well you can combine the functions of max_by and .count to get to this answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3LUHg0lb2M-yIOoP2LAgVw.png" /></figure><p>Above, you can see we asked that max_by iterate over all the writers in our Writer table. We asked that blogs connected to the writers be iterated over, and that the number of blog publications per writer be counted. This will then return the Writer with the most publications. This is an example of how powerful methods can be when you chain them together. Should you wish to determine the lowest number in a group of characteristics, you can use <strong>.min_by </strong>which is the opposite of .max_by. Just to reiterate, this just scratches the surface of Ruby methods, but hopefully you now understand how to use a few more.</p><p>Sources:</p><p>Ruby on Rails — Active Records. Tutorials Point</p><p><a href="https://www.tutorialspoint.com/ruby-on-rails/rails-active-records.htm#">https://www.tutorialspoint.com/ruby-on-rails/rails-active-records.htm#</a></p><p>How to Use the Rails Where Method (With Examples). Ruby Guides</p><p><a href="https://www.rubyguides.com/2019/07/rails-where-method/">https://www.rubyguides.com/2019/07/rails-where-method/</a></p><p>Ruby Enumerable max_by( ) function. Geeks for Geeks</p><p><a href="https://www.geeksforgeeks.org/ruby-enumerable-max_by-function/">https://www.geeksforgeeks.org/ruby-enumerable-max_by-function/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbd0c812e505" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Filter in React]]></title>
            <link>https://medium.com/@elainedoud/using-filter-in-react-3c1ba879f6a2?source=rss-8c6a9edfc159------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c1ba879f6a2</guid>
            <category><![CDATA[filters]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[state]]></category>
            <dc:creator><![CDATA[Elaine Doud]]></dc:creator>
            <pubDate>Sat, 26 Nov 2022 17:35:41 GMT</pubDate>
            <atom:updated>2022-11-26T17:35:41.966Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*zfRVBCcM_diCTQLX93VOtg.jpeg" /></figure><p>Filter is a useful function to use within React. It allows visitors to your website to easily find information, especially if there is a large amount from a database. The filter function is from JavaScript. The filter function allows you to iterate over an array and return what you request. In more technical terms, the filter function accepts a call-back function and uses it to test each component in the array. It does not change the original array. Instead, it allows a new array to be created (with certain components being removed) without altering the original array.</p><p>Within React, you must use state in order to make use of the filter function. State is necessary in order for the filter function itself to be triggered, and for the information of state that’s being changed to be saved. For our example, let’s say we have an array of planet names. On our website we’re displaying the names of planets along with an accompanying picture and short description. Our goal will be to have our website user be able to use a search-bar and search for a planet. If they type in “Mercury”, the name and image of Mercury will appear. In order to accomplish this, we will be making use of the Filter function to iterate over the initial array of the planets, and return the planet whose name matches what was placed in the search-bar.</p><p>The first step is setting our state. On our website, the code within React runs when the website loads and all the planets render. We will be setting up our code so when the state is changed, render will run again, and the new data, the planet we requested, will be displayed. Since we will be using a search-bar, to keep it simple we can call our variables “search” and “setSearch”. We will want to put an empty string (“ ”) within useState, because we will be capturing the information input into the search-bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*1C26p-GiQZ_cskhgBMDQcA.png" /></figure><p>The variables of search and setSearch will be used as props for the component of Search. Within the input section of Search, we will put the syntax for an onChange event and for saving a value. When information is input it will trigger the setSearch as well as saving the value to search. This information will be imported by Search back to the component that will need to use this with the filter method. The onChange event is crucial because this triggers the change of events that will lead to the selected information, in this case the planet we’re searching for, to be displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*Y547zAc0pc81M1-qrnpquw.png" /></figure><p>Now onto the exciting part — actually making our filter function. First, we want to create a new variable so we easily access and move our filtered information (filtered Planets) should we choose. Let’s keep it simple and call it “filteredPlanets”. Within this new variable we’re going to use our filter function. We want to filter over the data that was already rendering our planets. This data is already within a variable called planetData. So we will filter planetData and we will want to iterate over each element in the array, which we will refer to as “planet”. We will then input what we want the filter method to show, that is to return. We will request that it returns the planet by searching to match the planet name. To insure that a result is shown even if only part of the name is input (like if Merc is input rather than fully Mercury) we will want to put the function “includes” after planet.name. Within our overall component for our data, we will want to make our planetData now equal to our filteredPlanets in order to display the planet that was searched for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*lvV_A1uJxOA5bg3640jYww.png" /></figure><p>We have now successfully used the filter function to iterate over our planet data and return the planet that was searched for.</p><p>Sources:</p><p><em>How to Filter Data in React</em>. sebhastian.com</p><p><a href="https://sebhastian.com/react-filter/">How to filter data in React</a></p><p><em>Updating Arrays in State</em>. React Docs</p><p><a href="https://beta.reactjs.org/learn/updating-arrays-in-state">Updating Arrays in State</a></p><p><em>How to Manage React State with Arrays. </em>rw;eruch</p><p><a href="https://www.robinwieruch.de/react-state-array-add-update-remove/">https://www.robinwieruch.de/react-state-array-add-update-remove/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c1ba879f6a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scope]]></title>
            <link>https://medium.com/@elainedoud/scope-e0d0a031ef6d?source=rss-8c6a9edfc159------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0d0a031ef6d</guid>
            <category><![CDATA[scopes]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Elaine Doud]]></dc:creator>
            <pubDate>Sun, 30 Oct 2022 17:41:35 GMT</pubDate>
            <atom:updated>2022-10-31T13:22:19.174Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FftbCzTEkBXmTf0nirb%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FftbCzTEkBXmTf0nirb%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FftbCzTEkBXmTf0nirb%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c8f9d0f92fed3a5edaafd06430d3fc3/href">https://medium.com/media/5c8f9d0f92fed3a5edaafd06430d3fc3/href</a></iframe><p>As a new software developer, there have been several times when my code in JavaScript does not work and at first I am very puzzled as to why. In these instances it ended up being an issue of scope. As explained by W3Schools, functional scope means that if variables are declared within a function, they cannot be called or referenced outside that function. In contrast a global variable can be used anywhere else in your JavaScript environment. Attempting to call a local variable (ie. variable inside another function) may result in an error message or the code simply not working.</p><p>In theory this is straight forward, but when writing more complicated code it can become frustrating that a variable you declared earlier may not work as intended. As shown in the code below, the variable theGames was declared inside the function showGames. When I attempted to use the variable theGames when creating a new function it did not work. This is because it was already nestled inside another function. Once I moved the variable outside of the function by placing it at the top of my page, it became global, and I was able to use it in the rest of my code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9YlKvWg-c6Qd5iD6Tm-Ow.png" /></figure><p>Functions and objects also follow these rules regarding scope. A function nested within another function cannot be called elsewhere. The same goes for objects. If you create an object and are anticipating that you may need it again, declare it as a global variable rather than nesting it within a function. This helps us reach one of the goals of coding, which is to avoid repeating code when you can. It is an important, delicate balance to make sure your code is organized, but that you are also able to access what you need as you continue to add onto it.</p><p>It is also important to be aware that variable names nested within functions can be used elsewhere for different values. You can make use of this functionality if you choose, although this will likely make it more difficult to keep track of your variables. It will increase the chance of an error being made in the code. This is helpful to be aware of, because if you have a lot of code and are encountering errors, it is possible you may have inadvertently given two variables the same variable name.</p><p>Global scope is when your variables can be accessed anywhere in your code. Var, const, and let can all be used for global variables, but using either const or let is considered best practice. Local scope is when a variable can only be accessed within the function it is called in. Remember, objects and functions can also be variables. Block scope is when a variable can only be called from the block of code in which it was declared. A block of code in this case means between curly brackets { }.</p><p>Sources: <em>JavaScript</em> <em>Scope</em>. W3Schools. <a href="https://www.w3schools.com/js/js_scope.asp">https://www.w3schools.com/js/js_scope.asp</a></p><p><em>JavaScript Variable Scope. </em>Programiz.<em> </em><a href="https://www.programiz.com/javascript/variable-scope">https://www.programiz.com/javascript/variable-scope</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0d0a031ef6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>