<?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: royalterminal_</title>
    <description>The latest articles on DEV Community by royalterminal_ (@tyraino).</description>
    <link>https://dev.to/tyraino</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F464335%2F75acd52d-ec7d-4875-8ad0-49ee2dd35ca8.jpeg</url>
      <title>DEV Community: royalterminal_</title>
      <link>https://dev.to/tyraino</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tyraino"/>
    <language>en</language>
    <item>
      <title>Game Review Zone (update)</title>
      <dc:creator>royalterminal_</dc:creator>
      <pubDate>Fri, 20 Nov 2020 17:45:30 +0000</pubDate>
      <link>https://dev.to/tyraino/game-review-zone-update-4h1h</link>
      <guid>https://dev.to/tyraino/game-review-zone-update-4h1h</guid>
      <description>&lt;h2&gt;
  
  
  GRZ Updated
&lt;/h2&gt;

&lt;p&gt;Gaming Review Zone (GRZ - Pronounced as Gears) is a simple web app where you can create reviews about video games. I've created and built this project with Sinatra so I thought upgrading the code in Rails would be great idea!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Process
&lt;/h2&gt;

&lt;p&gt;I worked with Ruby on Rails along with &lt;code&gt;ActiveRecord&lt;/code&gt;. I used &lt;code&gt;devise&lt;/code&gt; to create my &lt;code&gt;User&lt;/code&gt; class which added all of my user authentication.&lt;/p&gt;

&lt;p&gt;I've created my &lt;code&gt;Reviews&lt;/code&gt; and &lt;code&gt;Games&lt;/code&gt; class and formed the &lt;code&gt;has_many&lt;/code&gt;, &lt;code&gt;belongs_to&lt;/code&gt;, and &lt;code&gt;has_many_through&lt;/code&gt; relationship between them. I've added validations and a custom validation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app &amp;gt; models &amp;gt; game.rb&lt;/span&gt;

  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:reviews&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;through: :reviews&lt;/span&gt;

  &lt;span class="n"&gt;validates&lt;/span&gt; &lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;presence: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;uniqueness: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;validates&lt;/span&gt; &lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;length: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;maximum: &lt;/span&gt;&lt;span class="mi"&gt;35&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;validate&lt;/span&gt; &lt;span class="ss"&gt;:is_title_case&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;is_title_case&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;any?&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;upcase&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
      &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"must be in title case"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I've added &lt;code&gt;Omniauth&lt;/code&gt; to the authentication system so users can be able to sign in with Google. I've added all of the necessary nested and non-nested routes in the config/routes directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# nested route&lt;/span&gt;

 &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:games&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; 
    &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="ss"&gt;:reviews&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;only: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:new&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:show&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Overall
&lt;/h2&gt;

&lt;p&gt;Being so comfortable with Sinatra, transitioning to Rails was a little tough. After working on this project, I was able to grasp it more. There's still so much to learn, but once again I've proved to myself that I can stick through.&lt;br&gt;
JavaScript here I come! ✨&lt;/p&gt;

&lt;h5&gt;
  
  
  Chapter 3 completed 🎉
&lt;/h5&gt;

&lt;h5&gt;
  
  
  ~ RoyalTerminal 👩🏾‍💻
&lt;/h5&gt;

&lt;h6&gt;
  
  
  // LEARN. LOVE. CODE. ♥
&lt;/h6&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>flatiron</category>
    </item>
    <item>
      <title>Gaming Review Zone </title>
      <dc:creator>royalterminal_</dc:creator>
      <pubDate>Wed, 16 Sep 2020 03:54:12 +0000</pubDate>
      <link>https://dev.to/tyraino/gaming-review-zone-5e38</link>
      <guid>https://dev.to/tyraino/gaming-review-zone-5e38</guid>
      <description>&lt;h1&gt;
  
  
  Built my first web application using Ruby
&lt;/h1&gt;

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

&lt;p&gt;Gaming Review Zone (GRZ - Pronounced as Gears) is a simple website where you can create reviews about video games. As a gamer, I thought this concept for my first web app would be perfect! &lt;/p&gt;

&lt;h2&gt;
  
  
  The process
&lt;/h2&gt;

&lt;p&gt;To keep it short and simple, &lt;code&gt;Sinatra&lt;/code&gt; is one of the web frameworks I used along with &lt;code&gt;ActiveRecord&lt;/code&gt; and &lt;code&gt;SQLite&lt;/code&gt;. To start my skeleton, I used the &lt;code&gt;corneal&lt;/code&gt; gem to generate the base of the application with all of my models, views, and controllers. &lt;/p&gt;

&lt;p&gt;I populated the database with my users, reviews, and upvotes table and formed &lt;code&gt;has_many&lt;/code&gt; and &lt;code&gt;belongs_to&lt;/code&gt; relationships between them. I implemented authentication/authorization for log in, log out functions and confirming the users identity. I added all of the necessary routes to all 4 controllers (application, reviews, sessions, users) and the necessary html for my views. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;.build&lt;/code&gt; Method
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;build&lt;/code&gt; method was something that was confusing to me. After searching high and low for examples, I finally have an idea on what it does.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;build&lt;/code&gt; works the same as &lt;code&gt;new&lt;/code&gt;, the only difference is &lt;code&gt;build&lt;/code&gt; instantiates the object's associations while &lt;code&gt;new&lt;/code&gt; only instantiates the object. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#tux

test = Review.new(game_title: "test", body: "test")

=&amp;gt; #&amp;lt;Review id: nil, user_id: nil, game_title: "test", body: "test", upvotes: nil, created_at: nil, updated_at: nil&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice how our &lt;code&gt;user_id&lt;/code&gt; is &lt;code&gt;nil&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@test = test.build_user(email: "test@test.com", username: "testy", password: "12345678")

=&amp;gt; #&amp;lt;User id: nil, email: "test@test.com", username: "testy", password_digest: "$2a$12$9AuPJRVMMaKCiNmHy7YUl.ncgA5YN5Cvj9lFhp/c1ho..."&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  &lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;I'm using &lt;code&gt;build_user&lt;/code&gt; since this is a &lt;code&gt;belongs_to&lt;/code&gt; relationship and not a &lt;code&gt;has_many&lt;/code&gt; relationship. Using &lt;code&gt;test.user.build&lt;/code&gt; will give you a &lt;code&gt;NoMethodError&lt;/code&gt;&lt;/em&gt;
&lt;/h5&gt;

&lt;h5&gt;
  
  
  &lt;em&gt;If I do &lt;code&gt;user.build_review(game_title: "test", body: "test")&lt;/code&gt; I will get an &lt;code&gt;NoMethodError&lt;/code&gt; as well, but &lt;code&gt;user.reviews.build(game_title: "test", body: "test")&lt;/code&gt; will work since it's a &lt;code&gt;has_many&lt;/code&gt; relationship.&lt;/em&gt;
&lt;/h5&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@test.save
=&amp;gt; true

@test
#&amp;lt;User id: 17, email: "test@test.com", username: "testy", password_digest: "$2a$12$w9Xx3M5/5pz57GKaOQl9e.WMTVZ2nKHsqDjoWWd6fCb..."&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  &lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;&lt;code&gt;build&lt;/code&gt; only returns the created object without saving it.&lt;/em&gt;
&lt;/h5&gt;

&lt;p&gt;Now they are associated. &lt;code&gt;build&lt;/code&gt; is just a neat way of associating your objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overall
&lt;/h2&gt;

&lt;p&gt;I had a few tweaks and hiccups, but altogether, working on the project wasn't as bad as I thought it would be. This is my second project, and since the first one, I've improved very much. I've spent more time working on cosmetics than the code itself, I've learned a lot, did tons of research, and had support to help me through the build. &lt;/p&gt;

&lt;p&gt;I know there's still a lot to learn, but working on this project definitely opened my eyes a little. I feel proud of myself for sticking through and not giving up. I'm fully ready to upgrade to Rails!&lt;/p&gt;

&lt;h5&gt;
  
  
  Chapter 2 Completed 🎉
&lt;/h5&gt;

&lt;h5&gt;
  
  
  ~ RoyalTerminal 👩🏾‍💻
&lt;/h5&gt;

&lt;h6&gt;
  
  
  // LEARN. LOVE. CODE. ♥
&lt;/h6&gt;

</description>
      <category>ruby</category>
      <category>activerecord</category>
      <category>sinatra</category>
      <category>flatiron</category>
    </item>
  </channel>
</rss>
