<?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 remi odufuye on Medium]]></title>
        <description><![CDATA[Stories by remi odufuye on Medium]]></description>
        <link>https://medium.com/@remi.odufuye?source=rss-308905baff00------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*R-ccHkhga15sohcX</url>
            <title>Stories by remi odufuye on Medium</title>
            <link>https://medium.com/@remi.odufuye?source=rss-308905baff00------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 08:44:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@remi.odufuye/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[Unable To Install MongoDB Locally]]></title>
            <link>https://medium.com/@remi.odufuye/unable-to-install-mongodb-locally-1e2c274e85fe?source=rss-308905baff00------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e2c274e85fe</guid>
            <dc:creator><![CDATA[remi odufuye]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 18:37:18 GMT</pubDate>
            <atom:updated>2020-04-13T18:37:18.362Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with MongoDB you can sign up with the cloud version using MongoDB Atlas . However if you wish to run a server locally on your MAC you may encounter an issue .</p><p>I hope this helps anyone having the same issue i ran into recently after upgrading my OS to Catalina</p><p>step 1 , go to mongo download page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k23D77jpzK47tOk5" /></figure><p>step 2 . go to MongoDb.com home page and then software — community software , pick current release and your OS version</p><p>So i had an issue setting up Mongo on my MAC .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n6odONB9EaO_aXq_" /></figure><p>After downloading , copy the files to your usr/local/bin folder . The next step will be to create a folder in the root directory by running this command in your current location</p><p>Step 3 . sudo mkdir /data/db .</p><p>Step 4 . Run the command sudo chown -R id -un /data/db</p><p>However these will fail if you are running the Catalina OS on your MAC ( see error below )</p><p>mkdir: /data: No such file or directory</p><p>What you may end up doing is running sudo mkdir data/db ( excluding the beginning ‘/’ )</p><p>This will ultimately create the directory , however its not the right approach as it should be a root folder . To confirm this will not work when you try running the mongod command it will fail as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4K2gaksPYKM7CMP0" /></figure><p>The issue is that the path /data/db is not found .</p><p>A simple work around will be to change the path by running as shown below</p><p>sudo mongod — dbpath=/usr/local/bin/data/db ( make sure you have the path created as stated in step 3 above )</p><p>The resulting output will be as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f1Oy0E-DryxtB7Vc" /></figure><p>This means that your Mongo Sever is now up and running , you can connect to a working console and open a mongo shell by opening up a new terminal and typing mongo</p><p>Result should be as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oZoaqQEhjFrFW7G1" /></figure><p>Clear screen by holding down Command + k and create a new database as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o13C_2mbCsCGioU8" /></figure><p>Hope This helps ….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e2c274e85fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WEBPAGE RENDERING IN JAVASCRIPT : PESSIMISTIC VS OPTIMISTIC]]></title>
            <link>https://medium.com/@remi.odufuye/webpage-rendering-in-javascript-pessimistic-vs-optimistic-578b3418122?source=rss-308905baff00------2</link>
            <guid isPermaLink="false">https://medium.com/p/578b3418122</guid>
            <category><![CDATA[dom-manipulation]]></category>
            <dc:creator><![CDATA[remi odufuye]]></dc:creator>
            <pubDate>Thu, 16 Jan 2020 10:16:40 GMT</pubDate>
            <atom:updated>2020-01-16T10:16:40.095Z</atom:updated>
            <content:encoded><![CDATA[<h3>WEBPAGE RENDERING IN JAVASCRIPT : PESSIMISTIC VS OPTIMISTIC</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rOxgqgko1FNjcn33.jpg" /></figure><p>The <strong>DOM</strong> (Document Object Model) is formed from the HTML that is received from a server. … Each of the <strong>rendering</strong> objects contains its corresponding <strong>DOM</strong> object (or a text block) plus the calculated styles. In other words, the <strong>render</strong> tree describes the visual representation of a <strong>DOM</strong>.</p><p>We start with an overview of browser actions when rendering a page:</p><p>Below we highlight how a browser renders a page</p><ol><li>The DOM (Document Object Model) is formed from the HTML that is received from a server.</li><li>Styles are loaded and parsed, forming the CSSOM (CSS Object Model).</li><li>On top of DOM and CSSOM, a rendering tree is created, which is a set of objects to be rendered (Webkit calls each of those a “renderer” or “render object”, while in Gecko it’s a “frame”). Render tree reflects the DOM structure except for invisible elements (like the &lt;head&gt; tag or elements that have display:none; set). Each text string is represented in the rendering tree as a separate renderer. Each of the rendering objects contains its corresponding DOM object (or a text block) plus the calculated styles. In other words, the render tree describes the visual representation of a DOM.</li><li>For each render tree element, its coordinates are calculated, which is called “layout”. Browsers use a flow method which only required one pass to layout all the elements (tables require more than one pass).</li><li>Finally, this gets actually displayed in a browser window, a process called “painting”.</li></ol><p>When users interact with a page, or scripts modify it, some of the aforementioned operations have to be repeated, as the underlying page structure changes.</p><p>When communicating with a server or fetching data from an external API , there are 2 ways that the data from the response received can be rendered unto the DOM</p><p><strong>Optimistic Rendering :</strong></p><p>lets say we have a function “IncreaseLikes” as shown below which is designed to update the inner text of a &lt;span&gt; element “<strong>likes</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1R4XHZLG4vzFw5rW" /></figure><p>in this case we write our code so that the DOM gets updated with the new value of LikesCount before the POST request is made . What this means is that if for some reason there is a connection failure , the API will not be updated even though the user can see new new value on the page . Once the page is refreshed it will show the old count since the update did not persist on the external API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q-EVcIjUhzCQDFiX" /></figure><p><strong>Pessimistic Rendering</strong></p><p>In this approach , we do not update the DOM until we receive a response from our API Call . From the example below we have a function “updateDescription” that takes in a new value “beerDescription” from a text field on a page . When the user updates the field and hits the “Edit Button” it calls this function and sends the new value to a local API ( in this case db.json file )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RXgB7g4Boyg4t3bf" /></figure><p>Once the “PATCH” request is completed and a response is received then the data is passed to the “RenderSingleBeer” function with the new value ( which will have persisted on the .json file )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DX60XuQ9lX2e9sfk" /></figure><p>See below extract from db.json file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M_-Da0t3G3PazmHv" /></figure><p>In Summary Optimistic rendering might give a better user experience since there is no need to wait for the server request / API Call to return the updated data before updating the page however it can be misleading if something interrupts the request while the Pessimistic approach may be less performant it ensures that what the user sees and the current state of the data are always in sync .</p><p><strong>References</strong><br><a href="http://frontendbabel.info/articles/webpage-rendering-101/">http://frontendbabel.info/articles/webpage-rendering-101/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=578b3418122" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WHAT’S THAT FUNCTION ?]]></title>
            <link>https://medium.com/@remi.odufuye/whats-that-function-1e0078cbffbf?source=rss-308905baff00------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e0078cbffbf</guid>
            <category><![CDATA[function]]></category>
            <category><![CDATA[arrow-functions]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[remi odufuye]]></dc:creator>
            <pubDate>Thu, 19 Dec 2019 10:07:09 GMT</pubDate>
            <atom:updated>2019-12-19T14:17:35.971Z</atom:updated>
            <content:encoded><![CDATA[<h3>WHAT’S THAT FUNCTION ?</h3><p><strong>A closer look At Function Declarations , Function Expressions and Arrow Functions .</strong></p><p>()=&gt; 🙂</p><p>In JavaScript these are concepts that have stumped me a bit and i still struggle with at times , however taking a closer look at them i have actually come to appreciate these concepts .</p><p>Learning the differences as well as how each works under the hood has helped me appreciate why we have them and the pros and cons of each one</p><ol><li><strong>Function Declaration</strong></li></ol><p><em>Function Declaration:</em> a function, declared as a separate statement, in the main code flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/0*k0r5dYNaLuTPWpaH" /></figure><p>A Function Declaration defines a named function variable without requiring variable assignment.</p><p>Just as Variable Declarations must start with “var”, Function Declarations must begin with “function”. We can even print out that value on the console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*qApMLpR_PSZj7ybA" /></figure><p>Please note that the last line does not run the function, because there are no parentheses after Greeting .There are programming languages where any mention of a function name causes its execution, but JavaScript is not like that.</p><p>In JavaScript, a function is a value, so we can deal with it as a value. The code above shows its string representation,</p><p>Surely, a function is a special value, in the sense that we can call it like Greetings().</p><p>But it’s still a value. So we can work with it like with other kinds of values.</p><p>We can also copy a function to another variable</p><p>2. <strong>Function Expression</strong></p><p>A Function Expression defines a function as a part of a larger expression syntax . Functions defined via Functions Expressions can be named or anonymous. Function Expressions must not start with the word “function”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/0*87_Jk8ueS49LmNe-" /></figure><p>Using the previous example from for function declarations , function expressions can also look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*n_u2xKACWGaKSYvAqdSeQw.png" /></figure><p>Here, the function is created and assigned to the variable explicitly, like any other value. No matter how the function is defined, it’s just a value stored in the variable greetings.</p><p>The meaning of these code is : “create a function and assign it into the variable greetings”.</p><p>3. <strong>Arrow Function</strong></p><p>This is another way of writing a function expression , it was introduced as part of ES6</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f2s02glk8Z2q1tEi" /></figure><p>Arrow functions can be used in the same way as Function Expressions.</p><p>Arrow functions may appear unfamiliar and not very readable at first, but that quickly changes as you get more familiar with the syntax</p><p>They are very convenient for simple one-line actions, and can be quicker than writing regular function expressions</p><p>M<strong>ain Difference Between Function Declarations and Function Expressions</strong></p><p>A Function Expression is created when the execution reaches it and is usable only from that moment.</p><p>Once the execution flow passes to the right side of the assignment , the function is created and can be used (invoked , called, etc. )<br>from now on.</p><p>Function Declarations are different.</p><p>A Function Declaration can be called earlier than it is defined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/0*5udKWmg9eMPZaQs2" /></figure><p>The Function Declaration labLover is created when JavaScript is preparing to start the script and is visible everywhere in it.</p><p>If it were a Function Expression, then it wouldn’t work:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xB4SdHOVUPLydx57" /></figure><p><strong>Summary</strong> ( Source : <a href="https://javascript.info/function-expressions">https://javascript.info/function-expression</a>s )<br>1. If the function is declared as a separate statement in the main code flow, that’s called a “Function Declaration”.<br>2. If the function is created as a part of an expression, it’s called a “Function Expression”.<br>3. Function Declarations are processed before the code block is executed. They are visible everywhere in the block.<br>4. Function Expressions are created when the execution flow reaches them.</p><p>Here is a neat tool that you can Use to Practice learning the differences</p><p><a href="https://thuyanduong.github.io/functions-quiz/"><strong>HTTPS://THUYANDUONG.GITHUB.IO/FUNCTIONS-QUIZ/</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TYrs0T0dIncVUyFq" /></figure><p>References :</p><ol><li><a href="https://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/">https://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/</a></li><li><a href="https://javascript.info/function-expressions">https://javascript.info/function-expressions</a></li><li><a href="https://javascript.info/arrow-functions-basics">https://javascript.info/arrow-functions-basic</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e0078cbffbf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RUBY ENUMERABLES]]></title>
            <link>https://medium.com/@remi.odufuye/ruby-enumerables-6bf0d7694832?source=rss-308905baff00------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bf0d7694832</guid>
            <category><![CDATA[enumerable]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[remi odufuye]]></dc:creator>
            <pubDate>Wed, 27 Nov 2019 16:30:57 GMT</pubDate>
            <atom:updated>2019-11-27T16:30:57.726Z</atom:updated>
            <content:encoded><![CDATA[<h4>HOW DO THEY WORK ?</h4><p><strong>Enumerables </strong>are a set of Modules in Ruby that allow us to traverse , search or sort over a collection of data . There are many methods which we can use to achieve this ( see full list in the ruby docs here : <a href="https://ruby-doc.org/core-2.6.5/Enumerable.html">https:</a><a href="https://ruby-doc.org/core-2.6.5/Enumerable.html">//ruby-doc.org/core-2.6.5/Enumerable.html </a>)</p><p>For someone who is new to this concept I think it’s important to learn how to use a few of these methods as opposed to trying to understand how they all work . Here are a few handy ones which you can use to achieve a lot .</p><ol><li><strong><em>THE EACH</em></strong></li></ol><p>The Each Method is used to move through or iterate over an array</p><p>west_coast = [&#39;warriors&#39;, &#39;clippers&#39;, &#39;lakers&#39;, &#39;pelicans&#39;]</p><p>west_coast.each do |team|</p><p>puts team</p><p>end</p><p>This will print out</p><p>#=&gt; warriors</p><p>#=&gt; clippers</p><p>#=&gt; lakers</p><p>#=&gt; pelicans</p><p><strong>Break Down Further :</strong></p><p><strong>each</strong></p><p>A method belonging to Array (in this case ‘west_coast’) . It’s also known as an iterator . it moves through a block which depends on the elements in the array</p><p><strong>do</strong></p><p>A Ruby keyword that signifies the beginning of a block of code</p><p><strong>|team|</strong></p><p>The variable names within the pipe characters are the arguments passed into the block. In the case of each, the single argument refers to the element in the current iteration.</p><p><strong>end</strong></p><p>Closes the block of code used by each.</p><p>3..<strong> THE SELECT</strong></p><p>This method takes in one argument. The block you pass it should be some kind of true/false test. If the expression results in true for an element in an array, that element is kept as part of the returned collection</p><p>Inside the block, you have to return something that evaluates to true or false, and select will use that to filter your array.</p><p>children = {</p><p>John: 10,</p><p>Kim: 5,</p><p>Mustapha: 2</p><p>}</p><p>children.select { |k, v| v &gt; 2 }</p><p>This prints</p><p>{:John =&gt;10, :Kim =&gt;5}</p><p><strong>3. THE FIND</strong></p><p>The find method is similar to select method in the sense that it traverses or iterates through a collection ( e.g hash or array ) and returns once an element satisfies the condition or nil if there are no elements that satisfy the condition</p><p>&gt; numbers = [1, 2, 3, 4, 5, 6]</p><p>=&gt; [1, 2, 3, 4, 5, 6]</p><p>&gt; hash = {&quot;a&quot; =&gt; 1, &quot;b&quot; =&gt; 2, &quot;c&quot; =&gt; 3}</p><p>=&gt; {&quot;a&quot; =&gt; 1, &quot;b&quot; =&gt; 2, &quot;c&quot; =&gt; 3}</p><p>&gt; numbers.find {|a| a &gt; 5}</p><p># returns the first element greater than 5 and `nil`</p><p>if none satisfies the condition</p><p>=&gt; 6</p><p>&gt; hash.find {|key, value| key == &quot;b&quot;}</p><p># returns an Array of the first match [key, value] that satisfies the condition</p><p>and nil otherwise</p><p>=&gt; [&quot;b&quot;, 2]</p><p><strong>4. THE REDUCE</strong></p><p>A popular requirement is to <strong>reduce</strong> a list of numbers into a single value by adding them together ( performing a sum operation). You can pass the <strong>reduce</strong> method a starting value (i.e. 0 in the example below), and a block. The way that works is, for each element of the array, the block gets two arguments</p><p>[1, 2, 3].reduce(0) { |sum, n| sum + n } # =&gt; 6</p><p>The way that works is, for each element of the array, the block gets two arguments. The first argument is the accumulator, the second is the current element. Another way to think about the accumulator is to think about it as a <em>running total</em>.</p><p>You can specify the accumulator starting value by passing it as the first argument to reduce. In the example above, the accumulator starts from 0. So let’s zoom in a little on how that works.</p><p>The first time reduce is executed, sum is 0.</p><p>So the last value of the accumulator is 6, which is also the value returned by the reduce method.</p><p>Also worth noting is the fact that if you don’t specify an initial value for the accumulator, it defaults to the first element of the collection.</p><p><strong>5. THE MAP</strong></p><p>This Method is used when you want a transformed copy of an array but you still want to preserve the original . Hence the main difference between <strong>map</strong> and <strong>each</strong> is t<em>hat map returns a transformed array</em> while each preserves the original array</p><p>numbers = [1,2,3,4,5,6]</p><p>numbers_arr.map do |numbers|</p><p>numbers * 10</p><p>end</p><p>This will print out</p><p>[10,20,30,40,50,60]</p><p>Break Down Further</p><p>The ‘do’ ‘end’ and ‘|number|’ in block does the same thing as .each only that the original array is preserved</p><p><strong>6. THE COLLECT</strong></p><p>Array#collect is same as Array#map and it applies the given block of code on all the items and returns the new array. Hence collect is for when you want to turn one array into another array</p><p>collect allows you to transform each element of your collection object (Array, Hash e.t.c) into something else, ending up with an Array.</p><p>See Example Below</p><p>(You can do this in either of the three ways )</p><p>arr=[1,2,3,4]</p><p>arr.collect {|x| x*2}</p><p>Returns [2,4,6,8]</p><p>[1, 2, 3,4].collect{ |num| num * 2 }</p><p># [2, 4, 6]</p><p>arr.collect do |num|</p><p>num * 2</p><p>end</p><p><strong>REFERENCES</strong></p><p><a href="https://rossta.net/blog/what-is-enumerator.html">https://rossta.net/blog/what-is-enumerator.html</a></p><p><a href="http://ruby.bastardsbook.com/chapters/enumerables/">http://ruby.bastardsbook.com/chapters/enumerables/</a></p><p><a href="https://mixandgo.com/learn/how-to-use-the-ruby-map-method">https://mixandgo.com/learn/how-to-use-the-ruby-map-method</a></p><p><a href="https://www.rubyguides.com/2019/04/">https://www.rubyguides.com/2019/04/</a></p><p><a href="https://www.hackerrank.com/challenges/ruby-enumerable-any-all-none-find/problem">https://www.hackerrank.com/challenges/ruby-enumerable-any-all-none-find/problem</a></p><p><a href="https://mixandgo.com/learn/what-is-a-ruby-reducer">https://mixandgo.com/learn/what-is-a-ruby-reducer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bf0d7694832" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RESTFUL ROUTES IN RAILS … The Magnificent 7]]></title>
            <link>https://medium.com/@remi.odufuye/restful-routes-in-rails-the-magnificent-7-33c5cc6390ab?source=rss-308905baff00------2</link>
            <guid isPermaLink="false">https://medium.com/p/33c5cc6390ab</guid>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[remi odufuye]]></dc:creator>
            <pubDate>Wed, 27 Nov 2019 16:22:55 GMT</pubDate>
            <atom:updated>2019-11-27T16:27:08.180Z</atom:updated>
            <content:encoded><![CDATA[<h3>RESTFUL ROUTES IN RAILS</h3><p><strong>REST</strong> (i.e. Representation State Transfer) is an architectural style for applications. The actions CRUD refers to all of the major functions implemented in relational database applications. In fact, each letter maps to a standard SQL statement.</p><p>Actions on database records are usually guided not by REST principles, but by CRUD.</p><p>CRUD is an abbreviation of <em>Create</em>, <em>Read</em>, <em>Update</em>, <em>Delete</em>, the four basic functions of persistent storage.</p><p><strong>REST</strong> uses <strong>HTTP</strong> requests to perform <strong>CRUD</strong> Operations</p><p><strong>HTTP requests</strong> : GET, PUT, POST and DELETE</p><p><strong>CRUD operations</strong> : CREATE , READ , UPDATE and DELETE</p><p>In other words it uses GET to retrieve a resource; PUT to change the state of or update a resource, POST to create that resource ; and DELETE to remove it.</p><p><strong><em>REST and CRUD are therefore two very different paradigms for two very different worlds.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RlzgZwJhg20Q-S8W.png" /></figure><p><strong>The Rails Router</strong></p><p>The Rails router recognizes URLs and dispatches them to a controller’s action, or to a Rack application. The Rails router is responsible for redirecting incoming requests to controller actions.</p><p>When your Rails application receives an incoming request for:</p><p>GET /patients/17</p><p>it asks the <strong>router</strong> to match it to a <strong>controller</strong> action. If the first matching route is:</p><p>get &#39;/patients/:id&#39;, to: &#39;patients#show&#39;</p><p>the request is dispatched to the patients controller’s show action with { id: &#39;17&#39; } in params.</p><p><strong>RESTful Rails</strong></p><p>A router in Rails is a directing module that recognizes browser URLs and dispatches them to the controller actions requested.</p><p>The Rails router is responsible for redirecting incoming requests to controller actions.</p><p><strong><em>The default resource routing in Rails allows you to declare all the basic routes for a certain controller with a single line of code</em></strong>. This means you do not have to declare all your routes separately for actions like <em>index</em>, <em>show</em>, <em>new</em>, <em>edit</em>, <em>create</em>, <em>update</em>, and <em>destroy</em>. The resourceful route will take care of that.</p><p>In Rails, <em>r</em><strong><em>esourceful routes</em></strong> provide the mapping between HTTP verbs and URLs and controller actions. These actions in turn map to <strong>CRUD</strong> operations in the database.</p><p>When a Rails application receives an HTTP request with a specific HTTP method such as GET, POST, PATCH, PUT, or DELETE, it asks the router to map it to a controller action. If the route is matched, Rails will dispatch that request.</p><p>An entry in the routes file <strong>config/routes.rb</strong> as shown below:</p><pre>resources :photos</pre><p>Creates by default <strong>seven different application routes </strong>mapping to the photos controller, as shown below</p><p><strong>a.k.a “ The Magnificent 7 “ …..</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/0*3OaUWjG_XZA4LVwY.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sgEvkXs5hwZo0gPWEQEWXg.png" /></figure><p>You can also use the :only and :except options to fine-tune the default Rails behavior of creating routes for the seven default actions (<em>index</em>, <em>show</em>, <em>new</em>, <em>create</em>, <em>edit</em>, <em>update</em>, and <em>destroy</em>). The :only option tells Rails to create only the specified routes:</p><pre>resources :categories, only: [:index, :show]</pre><p>The :except option specifies a route or list of routes that Rails should <em>not</em> create:</p><pre>resources :categories, except: [:destroy]</pre><p>In Summary , CRUD actions are mapped to the following HTTP actions , and rails allows you to define separate routes for each of your controller actions in a single line of code</p><ul><li>Create = PUT/POST</li><li>Read = GET</li><li>Update = POST/PUT/PATCH</li><li>Delete = DELETE</li></ul><p><strong>References :</strong></p><ol><li><a href="https://www.oreilly.com/library/view/restful-rails-development/9781491910849/ch04.html">https://www.oreilly.com/library/view/restful-rails-development/9781491910849/ch04.html</a></li><li><a href="https://guides.rubyonrails.org/routing.html">https://guides.rubyonrails.org/routing.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33c5cc6390ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>