<?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 Brooke Jones on Medium]]></title>
        <description><![CDATA[Stories by Brooke Jones on Medium]]></description>
        <link>https://medium.com/@runcode?source=rss-e2b0b248463b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-qPamEuzb1Rnhp9Y.JPG</url>
            <title>Stories by Brooke Jones on Medium</title>
            <link>https://medium.com/@runcode?source=rss-e2b0b248463b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 10:27:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@runcode/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[What the f*ck JavaScript?]]></title>
            <link>https://medium.com/@runcode/what-the-f-ck-javascript-fe20914cb6b?source=rss-e2b0b248463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe20914cb6b</guid>
            <category><![CDATA[javascript-coercion]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Brooke Jones]]></dc:creator>
            <pubDate>Thu, 08 Aug 2019 11:34:55 GMT</pubDate>
            <atom:updated>2019-08-08T11:48:33.599Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s explore…shall we?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*l6KDvk_e45fzL4egf_OMhA.png" /><figcaption>Image by Charlie Harvey</figcaption></figure><p>A few weeks ago I was searching the interwebs for a tutorial on JavaScript. I came across a Udemy course titled, “JavaScript: The Weird Parts”. Which immediately sent me down a deep, dark rabbit hole of google fun…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l84l6wjkANItXWqX.jpg" /><figcaption>M.W.Bassford</figcaption></figure><p>JavaScript is awesome. It’s a great language. It can do cool shit.</p><p>It is also quirky and has some really tricky parts to it. So why not have some fun exploring these quirks? Amiright?!</p><p>Here are a few examples — <strong>Before</strong> trying them out, see if you can guess what they each return. Trust me. You will enjoy this exercise.</p><p>Take a guess. Then run each separately and bask in the glow of JavaScript weirdness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*qNTOmozjbM3DVronHjFfnA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*KuxNAFYmK7TanMGnpazlMA.png" /></figure><p>Are we having fun yet?</p><p>Check this out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/128/1*RonR9V2431zgu63BFtn2_A.png" /></figure><p>How is an empty array equal to a not empty array?!</p><p><strong>Explanation: </strong>The abstract equality operator converts both sides to numbers to compare them, and both sides become the number 0 for different reasons. Arrays are truthy so, on the right, the opposite of a truthy value is false which is <a href="https://www.freecodecamp.org/news/js-type-coercion-explained-27ba3d9a2839/">coerced</a> to 0. On the left, an empty array is coerced to a number without becoming a boolean first, and empty arrays are coerced to 0, despite being truthy.</p><p>Here’s another classic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/215/1*18wF9NxI22lnDIXQ65zZtg.png" /></figure><p><strong>Explanation:</strong> The expression evaluates + (+”a”) as NaN.</p><p>Many of the examples of JavaScript weirdness that I found involved some sort of coercion. Because coercion is weird. So I of course asked google for more examples and came across this gem:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*jPP2fIDo_w8sGqRv75APWg.png" /><figcaption>WAT?!</figcaption></figure><p><em>To fully understand what’s happening here, you can reference the official </em><a href="https://www.ecma-international.org/ecma-262/6.0/"><em>ECMAScript specification</em></a><em> that JavaScript is built from.</em></p><p>Ok, let’s look more closely at what’s going on here.</p><p><strong>Block 1 — Introducing Coercion.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*WsihG8iTdNSJ60ayjg6qEQ.png" /></figure><p>If you run 0 == “0” in your console it will return true. But WHY?</p><p>0 is a number, and “0” is a string, they should <em>never</em> be the same! It doesn’t make sense!</p><p><strong>Explanation:</strong> When you compare two values using ==, one of the values may undergo <a href="https://www.valentinog.com/blog/coercion/"><strong><em>coercion</em></strong></a>.</p><blockquote><strong>Coercion </strong>— Automatically changing a value from one type to another.</blockquote><p><em>Automatically</em> is the key word here. Instead of you <em>explicitly</em> converting your types, JavaScript does it for you under the hood.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*LgnzKLds3ZCCvvb9.jpeg" /></figure><blockquote>if x is Number and y is String, return x == ToNumber(y)</blockquote><p>So in our case of <em>0 == &quot;0&quot;</em>:</p><blockquote>since 0 is Number and “0” is String, return <em>0 == ToNumber(&quot;0&quot;)</em></blockquote><p>Our string has secretly been converted to 0!</p><p>Weird, right? But wait…there’s more!</p><p><strong>Block 2 — Arrays are objects. Empty array becomes empty string.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*y9tfFy5QBbAojb7iugDEAA.png" /></figure><p>JS first looks for an object’s <strong>toString</strong> method to coerce it.</p><p>In the case of arrays, toString <em>joins all of its elements and returns them as a string.</em></p><p>Since our array is empty, we get:</p><blockquote><em>[].toString()</em></blockquote><blockquote><em>//&quot; &quot;</em></blockquote><p><strong>Empty string becomes 0.</strong></p><blockquote><em>0 == &quot; &quot;</em></blockquote><p>Since 0 is Number and “ “ is String, return <em>0 == ToNumber(&quot;&quot;)</em></p><p><em>ToNumber(&quot;&quot;)</em>returns 0.</p><p>so we have <em>0 == 0</em>. True.</p><p><strong>Block 3 — A Quick Recap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*UGe5DAG-n0ZyoECwe95oyg.png" /></figure><p><strong>Block 4 — FALSE!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*oF7SOcCjl6rOc0-ccZ1nyQ.png" /></figure><p>We have:</p><blockquote><em>&quot;0&quot; == []</em></blockquote><p>According to the docs:</p><blockquote>If x is String or Number and y is Object, return <em>x == ToPrimitive(y)</em></blockquote><p>so…</p><blockquote>Since “0” is String and [] is Object, return <em>x == ToPrimitive([])</em></blockquote><p>ToPrimitive([]) returns an empty string. So the comparison is now:</p><blockquote>&quot;0&quot; == &quot; &quot;</blockquote><p>They are now both strings, so coercion stops. Hence, we get <strong>FALSE.</strong></p><h3>What this means for us as developers.</h3><p>Use triple equals. <em>===</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w3NjBoI7rKWC8NnS.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/133/1*Lg0DYsjrC23srP0__oTacA.png" /><figcaption>Ah…that’s better!</figcaption></figure><p>== operator allows types coercion. It means that if two compared values are of different types, JS will try to coerce them to the same type before comparison. That extra keystroke is totally worth it!</p><p>This list is full of pretty silly things you can do as a developer. In 90% of use cases it’s better to avoid implicit type coercion. Consider this list as a learning exercise to test your knowledge on how type coercion works. If you’re bored, you can find more examples on <a href="https://wtfjs.com/">wtfjs.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe20914cb6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Running 100 Miles is Like Learning to Code]]></title>
            <link>https://medium.com/@runcode/how-running-100-miles-is-like-learning-to-code-2304f55cf636?source=rss-e2b0b248463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2304f55cf636</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[running]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Brooke Jones]]></dc:creator>
            <pubDate>Thu, 25 Jul 2019 17:40:35 GMT</pubDate>
            <atom:updated>2019-07-25T17:40:35.158Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_eYBSYT6F-ynEFM1tQutoA.jpeg" /><figcaption>Double Top 100 course. Fort Mountain State Park — the Cohutta Mountains in northern Georgia.</figcaption></figure><p>I love running insanely long distances.</p><p>I am also learning to code.</p><p>The enormity of each of these these adventures often catches me off guard, and I truly wonder if I’m actually able to do either. There’s no way I’m one of “those” people, capable of such incredible feats, of covering “I don’t even like to drive that far” distances on foot. Or, surely I’m not smart enough to learn how to be a software engineer…</p><p>Yet here I am.</p><p>I started running before I started coding. I had no idea that these two worlds would ever be related. But I was dead wrong. There are, in fact, many ways that the path to code overlaps with life in the mountains, and I routinely find myself relearning lessons I had previously encountered out on the trails. <strong>They all equally apply to coding.</strong></p><p>Here are a few.</p><h3>100 miles is really far. So don’t try to think about it.</h3><p>Anything and everything can happen in 100 miles.</p><p>The outcome is far from a given.</p><p>The thought of running 100 miles is absolutely daunting. But do you know what’s worse? The thought of running 70 more miles after you’ve already run 30. It’s soul crushing.</p><p>My advice: break your race up into smaller sections. Take the course loop by loop or aid station to aid station. It takes away the overwhelming enormity of tackling 100 miles.</p><p>The same is true with code. The mountain of information and skills to become a great developer seems like a never ending climb. There’s always more. But you can’t focus on allllll that you don’t know yet. Break it up. Focus on the small wins and successes. And move relentlessly forward. Eventually, you’ll look back and see just how far you’ve come.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*EDKts90EvXKSUSwqYEUCkg.jpeg" /></figure><h3>It is going to hurt.</h3><p>Without fail, in every ultra I do my legs start to hurt somewhere around mile 60. And without fail, every time I panic a little (“Holy sh*t this hurts and I still have x miles left to run!”) But I’ve found that each stage of “hurt” lingers for quite a while without getting worse. Eventually you become numb to that level of pain.</p><p>It’s right here, in this moment where you face your pain and ultimately make a decision. I could stop here and the suffering ends right now. Or…I could keep going.</p><blockquote><strong>Everything builds to this moment. When you’re stripped raw and think you’re done. That’s when the race really begins. That’s when you find out what you’re really made of.</strong></blockquote><p>When you’re at the point of both physically mentally wanting to quit. It all seems so impossible.</p><p>Remind yourself. This is why I am here.</p><p>To be challenged. To get to a point where it doesn’t feel easy anymore. Then you find something internal — that you’re able to overcome a challenge. If you can do that then it’s a whole lot more rewarding than if you just quit.</p><p>Keep coding. Keep going. It’s not easy. But it’s worth it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4uXPJ-NCDlFnq7Lch3aaLw.jpeg" /></figure><h3>You’ll question your life choices many times.</h3><p>Deep thoughts, such as “why didn’t I just take up scrapbooking?” or “If I was golfing, I’d be in the bar by now” will cross your mind a thousand times. You’ll wonder what on earth ever possessed you to believe that this was a good idea. You’ll wonder if there is some sort of damage to your frontal lobe, the part of your brain responsible for decision making…because clearly you aren’t very good at it.</p><p>You will get to that point where you wonder why you ever left your perfectly good career. Why leave the comfort of what is known for the discomfort of the unknown? Who does that?</p><p>We do it because a life of comfort isn’t worth being unhappy.</p><p>A little discomfort and pushing ourselves beyond what we thought were our limits is worth the effort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*cPeWOG-odQyp09ITy6qG0w.jpeg" /><figcaption>Mile 33 at Antelope Canyon 100 miler. In lots of pain with a hip injury and feeling it. Quick stop to take in some calories and fluids before heading back out.</figcaption></figure><h3>Math becomes really difficult.</h3><p>We lovingly refer to it as “ultra brain”.</p><p>When you’re sleep deprived and have been on your feet for nearly a day, it’s late at night and you’re somewhere in the middle of the woods trying to calculate if you’ll make the next time cutoff. Without fail, you will forget how to do basic math operations.</p><p>Mile splits, time cutoffs, how long you can slowly jog without dropping your average pace too far, distances to aid stations, it all becomes more confusing than a calculus midterm. My advice? Let your crew do the math.</p><p>Math in coding often seems like a challenge meant only for the truly gifted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*T4eesi0ahJEcpNVwF9kIzQ.jpeg" /><figcaption>- Cracking the Coding Interview by Gayle McDowell</figcaption></figure><h3>You’ll laugh really hard at stupid stuff.</h3><p>…the result of getting hit in the head too many times. OR running for 24+ hours without a break, take your pick. The most ridiculous things will become hilarious, like the color of your shoes or the way you can suddenly feel your cheeks jiggling when you run. Enjoy it. Laughing is so much more fun than crying. Which you’ll probably also do.</p><p>Debugging your code has a way of breaking you down and making everything seem either hilarious or excruciatingly awful. Make sure you choose the former, and learn to laugh at yourself when you’ve spent 30 minutes trying to debug an error only to find that you’ve added an ‘s’ to a variable that should be singular. It happens people. It happens…</p><h3>You’ll feel sorry for yourself.</h3><p>Even though this was your idea, you’ll probably have a few moments where you shed tears (in your mind or on your cheeks) over the misery you are currently feeling. A true “woe is me” experience. Take a minute to acknowledge the “suck”, and then get over yourself.</p><h3>You’ll sleep in weird places.</h3><p>The sleep deprived will take a nap anywhere they can.</p><p>2–3 minutes trail naps are life giving.</p><p>So are naps in your swivel chair at your desk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Fj90SG2fWnNz_Z7ynxC32g.jpeg" /></figure><h3>Self-talk can make or break you.</h3><p>You’re going to find both beauty and pain on the trails. (…and in your coding journey.)</p><p>Whatever you tell yourself, after a while, you start to believe.</p><p>Hours and hours of “this is hard, but I can do it”, “you got this”, or “what a great day” will tend to produce different results that “oh boy my legs feel heavy”, “I can’t figure out this error”, and “I’ll never be good at this.” Your mindset can turn into different performance results. It’s true that some people can rally when faced with criticism or difficulty, but they are rare. Most of us do far better with encouragement from the world around us AND our inner narrative.</p><p>Double down: Positive talk directed towards other people is a double shot of goodness. Telling other racers they’re doing well, thanking volunteers, small shouts of joy when cresting a tough climb, they all feeds into a big loop of sparkles and unicorns and love. And it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E86FBR0otbkOT27wdJyoRg.jpeg" /></figure><h3>Teamwork makes the dream work.</h3><p>You can certainly go at it alone. But life is best when it’s shared.</p><p>Race day is a special thing. On this day, we are all linked and unified by this one thing. This one journey. That’s a special bond.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OAM3iEeMGRNiE9Y5XfGrA.jpeg" /><figcaption>Climbing Mt. Baker at the end of the Georgia Jewel 50 miler with my friend Matt, my sister cheering me on from the side, and awesome race volunteers set up playing music on the steepest part of the climb.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*zjlTnF81OaZFDz5s8ztk2Q.jpeg" /><figcaption>My sister, and pacer, taking care of my feet around the 75 mile mark at the Yeti 100 mile in Damascus, VA.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J8HgxoF2GOxSMoadjGzebg.jpeg" /><figcaption>Most of our group from Flatiron’s Software Engineering Immersive Cohort in Atlanta.</figcaption></figure><p>Lean on others for support. Our mod at Flatiron has a special relationship and I truly don’t think that we’d be as successful without each other.</p><h3>You’ll redefine your relationship to suffering.</h3><p>We tend to think of suffering and joy as mutually exclusive- where there is suffering, there can be no joy. But in long distance running, I have experienced what I can only describe as<strong> joy *<em>in*</em> suffering.</strong></p><p>We harbor too simplistic an idea of what joy and suffering mean. Joy is not synonymous with happiness and suffering is not the same as pain. Joy is instead a deep sense of accomplishment when hard battles have been fought and we didn’t back down. It’s about submitting to a process of change.</p><h4><strong><em>The suffering is joyful.</em></strong></h4><p>In life, our task is not to eliminate suffering once and for all but to change our relationship to it. Those who seek to avoid suffering will find that they have not lived, while those who answer the call to suffer will have life in abundance. We are not to be saved from suffering, but to be saved in suffering.</p><p>Taking in mountaintop views that can only be reached my climbing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uo4ieLtKGVYCP7cQWWL2Iw.jpeg" /><figcaption>Somewhere on the Dragon’s Spine, after running overnight, cresting the top of one of the mountains just a the sun was rising. There’s literally nothing better than this moment.</figcaption></figure><h3>It will be worth it.</h3><p>When it’s you’re time, do you want to leave behind a well preserved body? Or do you really want to use it. A body with stories that says you’ve pushed it and at time suffered, and sought its potential.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*BG92-wL5buvqDvP2R2ylpQ.jpeg" /><figcaption>Finish line at Cloudland Canyon 50k.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*PvXi3sA0BvHE4HzV3FOz7g.jpeg" /><figcaption>Iron Horse finish line. My first 50 mile race…done!</figcaption></figure><p>It seems that, like the single minded focus of running down a mountain, to relief of seeing the sun starting to rise after a night out on the course, and the unbelievable fatigue after more than 24 hours of racing, the reason for doing it in the first place is beyond words. There is something that drives people to seek out a thing so hard, so emotional and raw that they can’t explain why but that thing defies explanation or articulation.</p><p>Go on that crazy, wild journey. Take the leap. Do the thing. And give it your ALL.</p><p>To give anything less than your best is to sacrifice the gift.</p><p>It’s going to feel extreme and uncomfortable. Get comfortable with being uncomfortable.</p><h3>…one last thing. Failure is temporary. It’s part of the journey. Don’t let it stop you.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*53hBWbHN0MkBvl7Ugp0iHw.jpeg" /><figcaption>My sister and I doing a shot after I had to drop about half way through the Antelope Canyon 100 miler with an injury.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2304f55cf636" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby on Rails: A Beginner’s Guide to Creating a Web App]]></title>
            <link>https://medium.com/@runcode/ruby-on-rails-a-beginners-guide-to-creating-a-web-app-eca59b0de94d?source=rss-e2b0b248463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/eca59b0de94d</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Brooke Jones]]></dc:creator>
            <pubDate>Thu, 11 Jul 2019 19:07:54 GMT</pubDate>
            <atom:updated>2019-07-11T19:07:54.779Z</atom:updated>
            <content:encoded><![CDATA[<p>A basic step-by-step how-to</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Ldy9OI0zsj3lXCcu0fDXw.png" /></figure><p>So you’ve decided to build a web application, awesome! Hopefully this post will prove helpful to you on your journey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*z23Hywl3lHLxaF9U4CM4eA.gif" /></figure><p>Simply put, RoR lets both Ruby and Rails lend us a hand to generate a fairly simple MVC pattern built on top of a CRUD approach when working with dynamic data.</p><p>Before we get started, let me introduce you to a very special friend:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/1*Zb-lg1nP2aP0eHlYu_8wKg.gif" /></figure><p>This is Manny the Mule, and he will be your cruel guide along this journey. He is harsh, but it’s meant with love. When you see Manny, you need to STOP reading and actually try to implement the functionality that was just covered. If you get stuck try these:</p><p>→ Refer to the <a href="https://guides.rubyonrails.org/index.html">documentation</a>.</p><p>→ Google. <a href="https://www.google.com/">Google</a> everything.</p><p>→ Try to just code, break stuff, and fix the bugs.</p><p>If you don’t try these steps whenever you see Manny, you’re just hindering yourself. Don’t do that. Be like Manny. Be awesome.</p><p>Ok, let’s get started.</p><p><em>(Make sure you have both Ruby and Rails installed on your computer.)</em></p><p>Go ahead and leverage those awesome Googling skills if you don’t have these yet. You’ve got this. Manny and I believe in you…</p><p>Create a new project in your terminal. Call it something meaningful. I’m going to be using the oh-so-creative “project_name”. Run each of the following commands separately:</p><pre>rails new project_name</pre><pre>cd project_name</pre><pre>bundle install</pre><pre>rails s</pre><p><em># this will get you up and running on </em><a href="http://l//localhost:3000"><em>http://localhost:3000</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EfCdvI7Lna8_RRn3feR44g.png" /><figcaption><a href="http://localhost:3000/">http://localhost:3000/</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/1*Zb-lg1nP2aP0eHlYu_8wKg.gif" /><figcaption>You know what yo do…</figcaption></figure><p>Yay! Now you can build just about anything you want!</p><p><strong>Rails Console.</strong> This is the interactive Ruby console — excellent for debugging! It can be accessed from the terminal using the command <strong><em>rails console</em></strong> or <strong><em>rails c</em></strong>.</p><p>A quick note about model names and table names. <strong>They are important. </strong>Rails has a pluralization engine to figure out what object maps to what table.</p><p><em>— Model names are singular.</em></p><p><em>— Database table names are plural.</em></p><p>I tell you this now to save yourself the hassle of fixing these things after starting a project…as I have done. By mistake. Loaded with regret.</p><p>You’re welcome.</p><p><strong>Models.</strong> Next, let’s generate some models. I’ll be using <em>pets</em> and <em>owners</em> as my two models. (Keeping it simple).</p><pre>rails g model Pet name:string image_url:string owner_id:integer<br>rails g model Owner first_name:string last_name:string</pre><p>This fancy command should have also created the migration files for each model. Magic!</p><p><strong>Relationships.</strong> You will need to set up the appropriate <a href="https://guides.rubyonrails.org/association_basics.html">relationships</a> for your classes.</p><p>In this case, we just have a simple one-to-many relationship. So, a pet belongs_to an owner. An owner has_many pets.</p><pre># in Pet model</pre><pre>  belongs_to :owner</pre><pre> ...</pre><pre># in Owner model<br>  <br>  has_many :pets</pre><p>Let’s get you caught up before we migrate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/1*Zb-lg1nP2aP0eHlYu_8wKg.gif" /><figcaption>You can do it!</figcaption></figure><p>Ok, now you’re ready to run:</p><pre>rails db:migrate</pre><p>At this point, any changes to your schema will require a rollback.</p><pre>rails db:rollback</pre><p>If you forgot to add your <strong>foreign key</strong> before you migrated, you can do a separate <a href="https://guides.rubyonrails.org/active_record_migrations.html">migration</a> like this:</p><ul><li><em>note: this is not the same as adding a regular column to your table. It’s the command specifically for a foreign key.</em></li></ul><pre>rails g migration add_owner_id_to_pets owner_id:integer</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/1*Zb-lg1nP2aP0eHlYu_8wKg.gif" /><figcaption>Kindly ask your computer to migrate for you. Compliments don’t hurt here. One can never be too careful when dealing with the database.</figcaption></figure><p><strong>Controllers.</strong> We can go ahead and create our <a href="https://guides.rubyonrails.org/action_controller_overview.html">controllers</a>. Run these commands separately…and watch some more magic happen!</p><pre>rails g controller Pets<br>rails g controller Owners</pre><ul><li><em>note the capital letter and pluralization.</em></li></ul><p>This will create the controller files as well as the view files for each! So no worrying about the names not matching! (For some of us…ahem…me, it’s me, this is a major point of contention, so it’s nice to have it taken care of automatically.)</p><p><strong>Routes. </strong>Let’s now make sure you have routes set up.</p><p>Routes are wonderful. Routes are the code that are responsible for listening and receiving requests and then deciding what to send back. The Rails router recognizes URLs and dispatches them to a controller’s action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views.</p><p>Go into the config folder and find the routes.rb file. Here, you’ll set up your routes by adding:</p><pre># in config/routes.rb<br>  ...<br>  resources :pets</pre><pre>  resources: owners<br>  ...</pre><p>This will allow all 7 RESTful routes.</p><blockquote>index, new, create, show, edit, update, destroy</blockquote><p>In general, CRUD actions are mapped to the following HTTP <a href="https://www.learnhowtoprogram.com/rails/ruby-on-rails-basics/rails-crud-create">actions</a>:</p><ul><li>Create = PUT/POST</li><li>Read = GET</li><li>Update = POST/PUT</li><li>Delete = DELETE</li></ul><pre>  get &quot;/pets&quot;, to: &quot;pets#index&quot;, <br>  get &quot;/pets/:id&quot;, to: &quot;pets#show&quot;<br>  get &quot;/pets/new&quot;, to: &quot;pets#new&quot;<br>  post &quot;/pets&quot;, to: &quot;pets#create&quot;  # usually a submitted form<br>  get &quot;/pets/:id/edit&quot;, to: &quot;pets#edit&quot;<br>  put &quot;/pets/:id&quot;, to: &quot;pets#update&quot; # usually a submitted form<br>  delete &quot;/pets/:id&quot;, to: &quot;pets#destroy&quot;</pre><p>You can run <strong><em>rails routes</em></strong> in your terminal to see all your routes. (Hint: this can be super helpful when using route helpers or when you get routing errors!)</p><p>You can come back later and limit these if you don’t use all of the RESTful routes:</p><pre>resources :pets, only: [:index, :show]<br>resources :owners, except: [:destroy]</pre><p><em>I could do a whole separate post about routes. (…especially route helpers!) For now, you can learn more about routing in the documentation </em><a href="https://guides.rubyonrails.org/routing.html"><em>here</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/1*Zb-lg1nP2aP0eHlYu_8wKg.gif" /><figcaption>Routes! Set those babies up!</figcaption></figure><p><strong>Seed Data</strong>. It’s not a terrible idea to <a href="https://davidmles.com/seeding-database-rails/">populate the database with some seed</a> data before you start building so that you can test each step as you go.</p><p>Go to the db/seeds.rb file.</p><p>Use the .create method to make some fake instances of each class. <em>(More posts to come on some cool ways to do this without writing a ton of lines of code!)</em></p><p>Now run:</p><pre>rails db:seed</pre><p>Voila! You can now run <em>rails console</em> and check your seed data to make sure the database populated correctly. (Example: Pet.all, or Owner.first)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/1*Zb-lg1nP2aP0eHlYu_8wKg.gif" /><figcaption>Go get your db up to snuff.</figcaption></figure><p>Now you, my friend, are ready to start building out your app!</p><p>Your controllers are sad and empty right now. But you can change that!</p><pre># in app/controllers/pets<br>  class PetsController &lt; ApplicationController<br><br>    def index<br>      # code to grab all posts so they can be<br>      # displayed in the Index view (index.html.erb)<br>    end<br><br>    def show<br>      # code to grab the proper Pet so it can be<br>      # displayed in the Show view (show.html.erb)<br>    end<br><br>    def new<br>      # code to create an empty pet and send the user<br>      # to the New view for it (new.html.erb), which will render a<br>      # form for creating the pet<br>    end<br><br>    def create<br>      # code to create a new pet based on the params that<br>      # were submitted with the form (and are now available in the<br>      # params hash)<br>    end<br><br>    def edit<br>      # code to find an existing pet we want and send the<br>      # user to the Edit view for it(edit.html.erb), which renders a<br>      # form for editing the pet<br>    end<br><br>    def update<br>      # code to figure out which pet we&#39;re trying to update, then<br>      # actually update the attributes of that pet.  Once that&#39;s<br>      # done, redirect us to somewhere like the Show page for that<br>      # pet<br>    end<br><br>    def destroy<br>      # code to find the pet we&#39;re referring to and<br>      # destroy it.  Once that&#39;s done, redirect us to somewhere fun.<br>    end</pre><pre>    private<br>     def pet_params<br>        params.require(:pet).permit(:name, :image_url, :owner_id)<br>     end<br>  end</pre><p>Awesome!</p><p>Now you can build this web app out however your heart desires! Have fun!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*KyC8tx9cl7ftKrPBf2wWGw.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eca59b0de94d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[!Plan to Fail]]></title>
            <link>https://medium.com/run-code/plan-to-fail-739dadbba07c?source=rss-e2b0b248463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/739dadbba07c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[women-who-code]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Brooke Jones]]></dc:creator>
            <pubDate>Thu, 20 Jun 2019 12:53:34 GMT</pubDate>
            <atom:updated>2019-06-20T13:36:37.545Z</atom:updated>
            <content:encoded><![CDATA[<p>An educator’s approach to coding</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*4Dsq2Li30XGkHp2TWH_ejA.gif" /></figure><p>I’m a former educator transitioning to a career in code.</p><p>After only a few short weeks into my coding bootcamp, I can already draw so many comparisons between teaching and coding. For starters, both fields will immediately break you and humble you to the very core of your soul. Aside from that tasty nugget, both are unexpectedly much more dependent on good planning skills over good technical skills. That seems weird. Let me explain…</p><p>When I first made the decision to take the leap, I started out, as many people often do, learning to code via online tutorials. These were all pretty straightforward, filled with mini-lessons and mini-challenges as you progress through modules. I would be taught how to do a certain kind of method, then immediately practice it in a very sheltered and safe environment. Things came pretty quickly. I was GETTING it! I pictured myself as one of those cool hackers in all the movies (could I actually be <em>that</em> cool??) I even had moments when I boldly dared to think to myself, “…maybe coding wasn’t all <em>that</em> hard.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*LUk1rE86l0opJjBpNAS-aQ.gif" /></figure><p>That’s cute.</p><p>I quickly realized the error of my ways as I completed the last few labs of my Flatiron School pre-work and started my Software Engineering Immersive program a couple of weeks ago.</p><p>Things got much more difficult reeeeaalllll quick.</p><p>It was not until after my first week of classes that I finally had a light-bulb moment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*AsUA6Vu223d5_AuLFbGfDw.gif" /></figure><p>I was still approaching the work the way that I was during those online tutorials. (And my first year of teaching.) I was immediately trying to jump right in and start writing methods, make classes, or create relationships between Ruby objects in code as soon as I finished — or, well, let’s be honest — barely skimmed the README for a lab. Did I so naively assume that beautiful, clean, and perfect code would just flow from my fingertips?? Oh my…</p><p>Well, I can tell you, it most certainly did not.</p><p>As I sat and struggled …and struggled …and struggled…I found myself slipping back into my “teacher mode”. I started to approach code in a different way:</p><p>Rather than rushing in to start writing lines of Ruby immediately, I stopped, slowed down, and I broke it into chunks and took time to think through the <strong><em>logic</em></strong> needed to solve the problem and <strong><em>plan</em></strong> my steps — just like I did when I planned for lessons as a teacher. Here’s the basic idea:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*Rz_Feppn8R1lfa8XeFy7oQ.jpeg" /><figcaption>Backwards planning approach</figcaption></figure><p>How can this approach be applied to code?</p><h3>1. What do I need to end up with?</h3><p><em>Start by thinking of </em><strong><em>what value you need returned</em></strong><em> from the method. (Beginning with the end in mind.)</em></p><h3>2. What do I currently have?</h3><p><em>How can I reference or work with this information?</em></p><h3>3. What steps do I need to take to get me from POINT A → POINT B?</h3><p><em>Take the overall problem and brake it down into detailed instructions that the computer can carry out. HINT: Pseudocode is a huge help here!</em></p><h3>4. Write some code. (test, edit…rinse, repeat)</h3><p><em>Learn how to test your code! Do not code blindly! You aren’t that good. :-)</em></p><p>The big takeaway here: Don’t think about programming as writing lines of code. Programming is a logic-based problem solving activity that <em>eventually</em> results in some code.</p><p>Let’s look at an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*yQ2K1_e27dlrw6cdzhxEyw.png" /></figure><p>I have two arrays and I’ve decided that I want to put them together to make a full sentence declaring my undying love for PB&amp;J’s.</p><p>Follow the steps</p><ol><li>What do I need to end up with? — I’ll need a longer string made up of the shorter strings in both arrays.</li><li>What do I currently have? — I have two different arrays, one assigned to the variable “a” and one assigned to the variable “b”. I notice that the strings seem to already be in some logical order — assuming I’ll be reading my PB&amp;J sentence like I would read a book. Cool.</li><li>What steps do I need to take to get from POINT A → POINT B? — Well, I need to know what methods I can call on arrays. So I’ll Google that. I found that the <a href="https://ruby-doc.org/core-1.9.3/Array.html">.join</a> method might be useful here — .join <em>returns a string</em> created by converting each element of the array to a string, separated by the given separator. Seems like we’ve got a good start here so pseudocode that out: array a + array b.join(with separator).</li><li>Write some code.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*Whk7TJbY-OJqIfsbv6YzJA.png" /></figure><p>To make it more readable I also added a new line at the end and printed what the method returns in the terminal so we can see it. Voila! CODE! — and most importantly — WORKING CODE!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*n7TilHpqGVtSTP6AZ0W4UQ.png" /></figure><p>Another example:</p><p>Let’s say you have a program relating artists, paintings, the art gallery, and the price of the paintings. We want to find the price of all the paintings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*qGVaCcSnbiXvVtV5CuOITQ.png" /></figure><ol><li>I know I need to return a value at the end of my method.</li><li>I have values currently. (In the instance variable that we set ‘@price = price’.)</li><li>So how can I break this down to get my desired result?</li></ol><ul><li>*Insert Google search here* and I find that the <strong>.reduce</strong> method can be used to take an array and reduce it to a single value. Perfect! (a.k.a. .inject method)</li></ul><p>The ‘0’ in the reduce argument sets the initial value. Cool, so I should be able to add the price of each painting to get a final total. Essentially…</p><p>start with <strong>sum = 0</strong> then iterate through the array of Paintings <strong>do |something| and add the price of each painting.</strong></p><p>4. Let’s write some code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*0SUBdTrHSbpbZZLy2A3d2w.png" /></figure><p>The .reduce method uses two parameters in the method |sum, painting|. The first parameter, ‘sum’, is the total that will eventually be returned from our method. The second parameter, ‘painting’, is the variable we iterate through from the array. So, with ‘sum + painting.price’ we are telling the method that we we want to add the price of each painting to the sum each time we iterate through the array.</p><p>Would I have come up with this off the top of my head? hahahahaha. no.</p><p>It took some planning and logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*dGBhbqfeGY1zlHnvNXox-A.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=739dadbba07c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/run-code/plan-to-fail-739dadbba07c">!Plan to Fail</a> was originally published in <a href="https://medium.com/run-code">Run &amp;&amp; Code</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>