<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Matt</title>
    <description>The latest articles on DEV Community by Matt (@mmccabe05).</description>
    <link>https://dev.to/mmccabe05</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1001345%2Fbc21bbc2-14f3-47dd-95f0-16df90b99625.jpeg</url>
      <title>DEV Community: Matt</title>
      <link>https://dev.to/mmccabe05</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mmccabe05"/>
    <language>en</language>
    <item>
      <title>Week 3: JavaScript basics</title>
      <dc:creator>Matt</dc:creator>
      <pubDate>Wed, 18 Jan 2023 03:00:53 +0000</pubDate>
      <link>https://dev.to/mmccabe05/week-3-javascript-basics-873</link>
      <guid>https://dev.to/mmccabe05/week-3-javascript-basics-873</guid>
      <description>&lt;p&gt;Some scattered and poorly formed notes from week 3, introducing JavaScript and AJAX. &lt;/p&gt;

&lt;p&gt;First, some basic differences between Ruby and JavaScript, first: introducing variables.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var_name = "1"

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

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let varName = "1"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second, &lt;a href="https://jquery.com/"&gt;jQuery&lt;/a&gt;, super powerful, much wow.&lt;/p&gt;

&lt;p&gt;Some reminder steps on transitioning to using AJAX with links (instead of full page refresh)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, insert &lt;code&gt;remote: true&lt;/code&gt; in the link helper (breaks the link)&lt;/li&gt;
&lt;li&gt;Make sure item has unique identifier&lt;/li&gt;
&lt;li&gt;in controller, add format.js to render a .js file (name conventionally and that's all you need)&lt;/li&gt;
&lt;li&gt;in the .js, call a method (e.g., slideUp()) on the unique identifier) for example...
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$("#&amp;lt;%= dom_id(@comment) %&amp;gt;").slideUp(2500, function() {
$(this).remove();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;dom_id() is a Rails function that fills in the object ID to make it easier to call the specific object for the action.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Using AJAX with forms is similar...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;update form to local: false in form_with&lt;/li&gt;
&lt;li&gt;same steps as above...&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Troubleshooting and where to look for errors (given Ruby exceptions are no longer present):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Server log - make sure request processes&lt;/li&gt;
&lt;li&gt;Devtools &amp;gt; JavaScript console (shows command line log) &amp;gt; Network tab (shows response from running .js)&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Week 2: intro to Ruby partials</title>
      <dc:creator>Matt</dc:creator>
      <pubDate>Wed, 11 Jan 2023 01:46:06 +0000</pubDate>
      <link>https://dev.to/mmccabe05/week-2-intro-to-ruby-partials-24f7</link>
      <guid>https://dev.to/mmccabe05/week-2-intro-to-ruby-partials-24f7</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= render partial: "zebra/elephant" %&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Partials&lt;/em&gt;&lt;/strong&gt; allow you to insert snippets of code into view templates to make them less bulky and incomprehensible. I'm thinking of these like old-school iframe tags in HTML but more powerful. It allows you to pull pieces of content from elsewhere to build with blocks instead of repainting each scene one by one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= render partial: "movies/form", locals: { movie: @movie  } %&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;More powerful though is the ability to pass variables through locals to partials. In the example above, we're saying render a snippet of code with a standard form to update a Movie object in our database. Because we want to edit an existing movie we're passing it the variable movie: and sending it the @movie value. The @movie variable comes from the params hash, it's available because we're taking a route which defines @movie within the Movie controller using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; @movie = Movie.find(params.fetch(:id))

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

&lt;/div&gt;



&lt;p&gt;So, the flow is &lt;/p&gt;

&lt;p&gt;Route -&amp;gt; movies/8/edit/&lt;br&gt;
goes to the routes.rb file&lt;br&gt;
follows the "edit" route and passes "8" to the :id variable in the params hash.&lt;br&gt;
then it runs the edit function within the movies controller...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; def edit
    @movie = Movie.find(params.fetch(:id))
  end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which then assigns @movie an Active Record relation that matches the movie with id "8". &lt;strong&gt;&lt;em&gt;That&lt;/em&gt;&lt;/strong&gt; allows the snipped of code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;%= render partial: "movies/form", locals: { movie: @movie  } %&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;to use @movie when passing it to the partial that runs the form&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;lt;% movie.errors.full_messages.each do |message| %&amp;gt;
  &amp;lt;p class="alert alert-danger w-50 mt-4"&amp;gt;&amp;lt;%= message %&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;% end %&amp;gt;

&amp;lt;%= form_with model: movie do |form| %&amp;gt;
  &amp;lt;div&amp;gt;
    &amp;lt;%= form.label :title %&amp;gt;
    &amp;lt;%= form.text_field :title %&amp;gt;
  &amp;lt;/div&amp;gt;

  &amp;lt;div&amp;gt;
    &amp;lt;%= form.label :description %&amp;gt;
    &amp;lt;%= form.text_area :description %&amp;gt;
  &amp;lt;/div&amp;gt;

  &amp;lt;div&amp;gt;
    &amp;lt;%= form.submit class: "btn-primary" %&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;% end %&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;tl;dr the local variable in the template that calls in the partial &lt;strong&gt;&lt;em&gt;must&lt;/em&gt;&lt;/strong&gt; match the element within the partial you're calling to activate.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Notes from class 1</title>
      <dc:creator>Matt</dc:creator>
      <pubDate>Wed, 04 Jan 2023 03:09:01 +0000</pubDate>
      <link>https://dev.to/mmccabe05/notes-from-class-1-250h</link>
      <guid>https://dev.to/mmccabe05/notes-from-class-1-250h</guid>
      <description>&lt;p&gt;Back on the horse. Today we jumped into refactoring code we learned in App Dev 1, in particular improving form functionality. One item of note was the addition of authenticity tokens to forms to add security such that other sites can't grab a form and submit unrelated content for a database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="hidden" name="authenticity_token" value="&amp;lt;%= form_authenticity_token %&amp;gt;" &amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ruby pulls the token from that method that is called in-line within the form. &lt;/p&gt;

&lt;h3&gt;GitPod shortcut of the week&lt;/h3&gt;

&lt;p&gt;Select some text and then press Command + D selects the next instance of identical text in the document, using arrow keys you can then edit multiple lines at the same time. &lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>Hello, world.</title>
      <dc:creator>Matt</dc:creator>
      <pubDate>Wed, 04 Jan 2023 00:29:18 +0000</pubDate>
      <link>https://dev.to/mmccabe05/hello-world-2o7e</link>
      <guid>https://dev.to/mmccabe05/hello-world-2o7e</guid>
      <description>&lt;p&gt;Today is day one of App Dev 2. Here we go.&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
  </channel>
</rss>
