<?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: Robin Vernon</title>
    <description>The latest articles on DEV Community by Robin Vernon (@robinlashae1).</description>
    <link>https://dev.to/robinlashae1</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%2F768337%2Fa8cbeab3-1ef9-4ca9-aca8-d62686ac7aa1.jpeg</url>
      <title>DEV Community: Robin Vernon</title>
      <link>https://dev.to/robinlashae1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/robinlashae1"/>
    <language>en</language>
    <item>
      <title>Let’s talk Relations</title>
      <dc:creator>Robin Vernon</dc:creator>
      <pubDate>Mon, 11 Apr 2022 20:06:13 +0000</pubDate>
      <link>https://dev.to/robinlashae1/lets-talk-relations-427c</link>
      <guid>https://dev.to/robinlashae1/lets-talk-relations-427c</guid>
      <description>&lt;p&gt;When getting started on a Ruby or Rails app, you may find that you have many tables that correlate. For example, let’s say we are making an app for a football team, this team plays in many games throughout the season but has their own stadium in their city. If we wanted to show the relation in a rails, we would use the macros in the Teams model:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Belongs_to&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can use this macro to state that the team belongs to a specific city. (Notice that city is singular)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Belongs_to :city&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Has_many&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We use this to show that the Football team participates in many games throughout the season. With this relation, we could call TeamName.Games.All and the console would return all games the team has participated in.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Has_many :games&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Has_many.    , through:&lt;/strong&gt;&lt;br&gt;
We can use this macro to show nested relations or relations that happen through an already associated relation. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Has_many :points, through: :games&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now if we seeded our DB to display points for each team(that would be a lot of instances), I would be able to call &lt;br&gt;
TeamName.Points.All and the console would return the points from each game. This is because we now have access to points, through the games class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple enough right? If you found this informative, I’d love to hear your feedback.&lt;/strong&gt;&lt;br&gt;
Check out my github to see how i use these macros:&lt;br&gt;
&lt;a href="https://github.com/robinlashae1"&gt;https://github.com/robinlashae1&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React: Components</title>
      <dc:creator>Robin Vernon</dc:creator>
      <pubDate>Mon, 21 Mar 2022 06:02:47 +0000</pubDate>
      <link>https://dev.to/robinlashae1/react-components-e2g</link>
      <guid>https://dev.to/robinlashae1/react-components-e2g</guid>
      <description>&lt;p&gt;When first learning React, a key concept you’ll encounter are components. These are essentially building blocks for your app. They help to make your code “dry”, dynamic and are an essential part of what developers like to call SOC, or separation of concern. To truly understand how powerful components are, it’s important to know why we use them. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Dry Code?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The term “Dry” code refers to the principle that &lt;em&gt;it is both a bad practice and a waste of time to repeat yourself in coding&lt;/em&gt;. The excess amount of code we get when we overwrite can lead to a major decrease in readability and more room for bugs. Instead we prefer to keep out code D.R.Y, and one way we can do that is with react components. With these components, we can create reusable functions that can be referenced and passed down to cut out extra wording. This helps to make our code dynamic, which by definition is “characterized by constant change, activity, or progress”. In development, this just means, “can your code adapt to change?”. With components and props, this is very possible, especially with the help of dry code. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fdSpJX05--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9rvr5edolx74tyenv1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fdSpJX05--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9rvr5edolx74tyenv1u.png" alt="Image description" width="686" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is SoC?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Development, this is the principle of separating your program into different sections based on what they accomplish. In theory, it’s possible to have everything in one place, but that would probably be chaotic. The readability of that app would be exhausting and it would be so hard to debug. Instead, we use components to separate our concerns and focus solely on them. This is very important here, because we wouldn’t want to code our filter feature in the same place we’re adding a form/add/delete feature. This lest us organize in a way that is beneficial for us and whoever else will read our code. After we’ve accomplished what we want, we can simply call this component in our parent app to render it correctly.  Separation of concerns is such an easy way to avoid confusion and make an app more organized. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rcBrbRu0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2edo3bnowtkvpdyo1uss.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rcBrbRu0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2edo3bnowtkvpdyo1uss.jpg" alt="Image description" width="400" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;What advise do you wish you knew when starting with react? Open to feedback.&lt;/strong&gt;&lt;br&gt;
check out my github to see some of my react apps:&lt;br&gt;
&lt;a href="https://github.com/robinlashae1"&gt;https://github.com/robinlashae1&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>component</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Basic guide to Active Record Commands</title>
      <dc:creator>Robin Vernon</dc:creator>
      <pubDate>Mon, 21 Mar 2022 05:55:43 +0000</pubDate>
      <link>https://dev.to/robinlashae1/a-basic-guide-to-active-record-commands-doh</link>
      <guid>https://dev.to/robinlashae1/a-basic-guide-to-active-record-commands-doh</guid>
      <description>&lt;p&gt;When transitioning to Ruby’s active record, the commands can be a little long winded and tedious. Here i have provided a cheat sheet to basic AR commands&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Classes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When working with Active Record and making classes, often we will have to write methods, below are some of the basic methods you will most likely encounter along. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;.column_names&lt;/code&gt;&lt;br&gt;
Retrieve a list of all the columns in the table&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.create&lt;/code&gt;&lt;br&gt;
Create a new entry in the database and saves it&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.all&lt;/code&gt;&lt;br&gt;
Return all the desired instances of the class from the table &lt;/p&gt;

&lt;p&gt;&lt;code&gt;.find&lt;/code&gt;&lt;br&gt;
Retrieve an instance from the database by id&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.find_by&lt;/code&gt;&lt;br&gt;
Find by any attribute(ie. name)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.Attr_accessors&lt;/code&gt;&lt;br&gt;
You can get or set attributes of an instance&lt;/p&gt;

&lt;p&gt;&lt;code&gt;#save&lt;/code&gt;&lt;br&gt;
save changes to the database&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.Find_or_create_by&lt;/code&gt;&lt;br&gt;
Finds the first instance with the given attributes, or creates a instance with the attributes if one does not exist&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rake&lt;/strong&gt;&lt;br&gt;
Using rake commands can sometimes get a little confusing, especially with the bundle exec prefix, these are the task you’ll likely encounter most&lt;/p&gt;

&lt;p&gt;Create migration&lt;br&gt;
&lt;code&gt;bundle exec rake db:create_migration NAME=&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Migrate&lt;br&gt;
&lt;code&gt;bundle exec rake db:migrate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create Table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create_table :modelName do |t|

      t.string :name

      t.string :genre

      t.integer :age

      t.string :hometown

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

&lt;/div&gt;



&lt;p&gt;Check status&lt;br&gt;
&lt;code&gt;bundle exec rake db:migrate:status&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Rollback&lt;br&gt;
&lt;code&gt;bundle exec rake db:rollback&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Running a seed file&lt;br&gt;
&lt;code&gt;bundle exec rake db:seed&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or to replant with new data &lt;br&gt;
&lt;code&gt;bundle exec rake db:seed:replant&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Looping faker gem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another amazing tool we can use is the faker gem, once we have created our migrations and tables, we can use this gem in the seed file to fill our tables with dummy data. This is particularly useful when wanting to test methods&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;50.times do

  # create a movie with random data

  Movie.create(

    title: Faker::Movie.title,

    genre: Faker::Movie.genre,

    ticket_price: rand(0..20) # random number between 0 and 20

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

&lt;/div&gt;



&lt;p&gt;end&lt;/p&gt;

&lt;p&gt;Though this isnt everything, hopefully this will help you when diving into ORM!! Happy coding!&lt;br&gt;
check out my github to see how i utilize these:&lt;br&gt;
&lt;a href="https://github.com/robinlashae1"&gt;https://github.com/robinlashae1&lt;/a&gt;&lt;/p&gt;

</description>
      <category>activerecord</category>
      <category>guide</category>
      <category>cheatsheet</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Instance Vs. Class</title>
      <dc:creator>Robin Vernon</dc:creator>
      <pubDate>Wed, 16 Mar 2022 03:59:56 +0000</pubDate>
      <link>https://dev.to/robinlashae1/instance-vs-class-1lp9</link>
      <guid>https://dev.to/robinlashae1/instance-vs-class-1lp9</guid>
      <description>&lt;p&gt;On introduction, the idea of instances and classes can seem overwhelming. However, they are actually quite simple concepts to understand over time. Let’s take a step back, and look at them in another light.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Class?&lt;/strong&gt;&lt;br&gt;
A class is in practice, a blueprint while an instance is a single occurrence of a class. Let’s think about it like this, when creating a table for a car class, I might say it has a make, model, color, and a year. These attributes would be defined in our table and permitted in our create method. These blueprints aren't the actual car, instead they lay out step by step what every car should consist of and give us other helpful information (Class Methods) to be used in creation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is an Instance?&lt;/strong&gt;&lt;br&gt;
An instance is the product of a class. For example, an instance of our Cars class could be a black 2019 Dodge Charger. Another instance could be a 1993 red Chevy. These are all single occurrences of the cars class, all following the specific blueprint we created. These instances are all unique in value, but they still share the same attributes. If we were to strip the instances down to their very basic mold, they have a make, model, color and year. This is how the blueprint is used. &lt;br&gt;
&lt;strong&gt;How to create an instance:&lt;/strong&gt;&lt;br&gt;
Using our previous Car class and assuming string types for all except year, we could use .create&lt;br&gt;
&lt;code&gt;Car.create(make: "Dodge",model: "Charger",color: "Matte Black",year: 2015)&lt;/code&gt;&lt;br&gt;
&lt;em&gt;or we could assign an instance to a variable:&lt;/em&gt;&lt;br&gt;
assuming we have setter and getter methods in our class file&lt;br&gt;
&lt;code&gt;attr_reader :make, :model, :color, :year&lt;/code&gt;&lt;br&gt;
we could go the following in our rails console&lt;br&gt;
&lt;code&gt;my_new_car = Car.new&lt;br&gt;
my_new_car.make= "Dodge"&lt;br&gt;
my_new_car.model= "Charger"&lt;br&gt;
my_new_car.color= "Blue"&lt;br&gt;
my_new_car.year= 2015&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sBJ_u3pu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ks8hikan2csqg2osrgg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sBJ_u3pu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ks8hikan2csqg2osrgg.png" alt="Image description" width="880" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which way do you like more? Open to feedback.&lt;/strong&gt;&lt;br&gt;
check out my github to see which method I like most:&lt;br&gt;
&lt;a href="https://github.com/robinlashae1"&gt;https://github.com/robinlashae1&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Renaming a Rails app</title>
      <dc:creator>Robin Vernon</dc:creator>
      <pubDate>Sun, 19 Dec 2021 20:38:14 +0000</pubDate>
      <link>https://dev.to/robinlashae1/renaming-a-rails-app-3fg0</link>
      <guid>https://dev.to/robinlashae1/renaming-a-rails-app-3fg0</guid>
      <description>&lt;p&gt;Have you ever began a project without having a solid name picked out? I'm sure all of us have at least once. This is completely ok, we shouldn't just let inspiration fade because we can't think of a application name. Once an appropriate name sticks with you, it's time to rename your application. When trying you do this manually, you'll find that this really isn't an easy thing to do. However, thanks to &lt;a href="https://github.com/morshedalam/rename"&gt;Morshed Alam's "rename" gem&lt;/a&gt; , all the dirty work is done for us. This gem goes through your application and relabels where appropriate.&lt;br&gt;
&lt;strong&gt;HOW TO:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add this to your gemfile&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;gem "rename"&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rename your app&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;rails g rename:app_to updated_name&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Optional&lt;/em&gt; Rename your Database
(in order to do this, you must be logged into Postgresql)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;ALTER DATABASE db_name RENAME TO new_db_name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And Voila, you're done. Please note that the app you're currently in will no longer be useable. Navigate to the directory this file is in and your newly named app should be there!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Is there anything that you would do differently? Did this work for you? Open to feedback Devs!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
