Ruby on Rails – Git & Github

I’m just using this to document what I’m doing to help solidify the work in my head. I’m also likely to come back here to reference different steps…

To be able to back up and save your program, I’m going to use github.com. The first thing you have to do is set up your ssh (which stands for secure shell). You can use the command cat ~/.ssh/id_rsa.pub in the terminal. You then have to copy the code that is printed. Got to github, click to add a new SSH, and paste the code into the field. Once that is done, you should make a repository for each of the programs you will work on.

To create a new repository, you need to click on the “+” sign in the top right corner of github.com and choose “New repository”.  Name the repository something that makes sense (probably the name of your program).  You’ll then want to follow the instructions to “push an existing repository from the command line”.

Before you can actually “push” your changes to a repository with git, you have to “commit” the changes. git status can always show you what files have been modified. Use git add -A to add a file to your local repository (local repo). Then use git commit -m "note to remind you what this is for" to commit that local repo. This just “saves” your changes, but it hasn’t uploaded it to github. To “upload” it to github, use git push to push the files to github.

Right now, I’m able to fire up a rails server and see what I’ve created in my own browser, but that is all local, nothing to show others or see online.  If I want to be able to show it to others, I need to deploy to production.  I’ll be using Heroku (which is a very common site to use) for this.

Notes for Rails – creating a new page

Just for those following along, I’m learning how to create a new app: How to create a new Rails application: rails new test_app (where “test_app” is the name of the program) and add an html to that page.

I first have to make a new route in the config folder in my new app.  I do that by loading my app in Atom (or a similar editor) and drilling down in the file tree to the config folder.  Open routes.rb and create a new path by typing get 'pages/home', to: 'pages#home'. This creates the route, but now I’ll need a controller and a view. To create a controller, find the controllers folder which is nested inside the app folder. Inside that folder, I’ll need to make a new file called pages_controller.rb. Once that file is created, I’ll need to put the following code in to inherit the stuff from the ApplicationController:
class PagesController < ApplicationController
end

Then inside the pages_controller.rb file and inside the class PagesController, I’ll need to define the action(method): home.
class PagesController < ApplicationController
  def home
  end
end

The last thing I need to create is the template for the page. Navigate to the views folder and create a new folder titled pages. Inside that folder create a new file titled home.html.erb. That page is the actual webpage, so put “This is the home page”(or whatever you want).

One additional note: to add a ruby code to a .erb file, you have to put the code between <% and %> brackets.  If you want the code to actually show something on the screen of a web browser, the open bracket should be <%= and closing should be %>.  A link would be: <%= link_to 'Home Page', pages_home_path %> where 'Home Page' (is the text that will be the link) and pages_home_path is the path to the controller (pages) and the action or method (home) - which will get you to the actual Home Page.  Don't forget the comma between the two (I wasted 15 minutes forgetting that earlier)...

Also... instead of having to type 0.0.0.0:3000 to see the rails server, and then having to type 0.0.0.0:3000/pages/home to get to the home page, you can make 0.0.0.0:3000 be the home page.  You just have to go to the routes.rb (in the config folder and change the code from this:
get 'pages/home', to: 'pages#home' 
to this:
root 'pages#home'.
Once that is changed, make sure to update the path to <%= link_to 'Home Page', root_path %>

Ruby on Rails – progress #1

Image result for ruby on rails image

I’ve been enjoying the Udemy course so far, learning about methods, arrays, branching, iterators, and hashes.  So far things have made sense, and there have been a few small projects to work through that have made sense.  My brother gave me another suggestion today for another course.  This one is from FlatIron School and is called Coding Bootcamp Prep.  There also looks to be an Intro to Ruby but I’m guessing that what I’m learning with the Udemy course would cover all the basics.  I’m looking forward to having enough knowledge under my belt to start making my own program.  The course also gave another recommendation of a site to hone your basic skills: GitHub TryRuby.  Seems pretty doable.

Ruby on Rails – installation

I decided to take the plunge and shell out the $10 for a $200 Udemy class.  It has a lot of good ratings and I think it will be a good way to get to learn more about Ruby on Rails.  There are over 40 hours of video instructions and I’ve been able to follow along quite easily with them so far.  I’ve found that I’ve been watching a lot of TV recently and decided that I should probably cut back a bit or at least multitask and learn something with the extra time.  So Rails it is.  

My main goal is write a web app that will allow me to keep track of my Singles Tennis Ladder in a cleaner nicer way.  I think that should be pretty doable.  Another project I could work on is an attendance program for school (which we surprisingly don’t currently have).

The first thing I had to do was update my version of Ruby and Rails (and Homebrew) but after some googling, I was able to do it pretty easily.  I did have a slight hiccup with Homebrew. I kept getting an error that I didn’t have permission to write to /usr/local/, but after uninstalling and reinstalling, that took care of the issue.  I finally got it installed on my local machine and I’m ready to start learning some Rails!

Rainbow is her favorite color

If you know anything about my girl, she loves unicorns, slime, and rainbows.  She has declared rainbow her favorite color  .  Her brother, being the loving brother that he is, got her a rainbow craft for Christmas.  He was determined to get her a box of crayons and a canvas so that they could make a piece of art together.  We all finished it together last night and it came out great!  Good job, Paco! 

It was really fun to see how excited both the kids were to find gifts for others and how much joy it brought them to give those presents to others.  I felt like this was truly the first year they both got the importance of thinking of others not always being interested in receiving, but instead giving!

Ruby on Rails

I’ve always been interested in coding and try to teach myself different languages at different times.  I’ve dabbled in Ruby a while ago, but don’t remember a ton.  But I want to get better and would like to write a web app for our Tennis Singles Ladder (which is currently running using a Google Sheet).  It works for what we need it for, but I thought it would be nice to convert it to something a little bit shinier (and a project for me to build while learning a language).  But to start, I need a short refresher course.  So I googled the best ways to learn Ruby.  I’m going to keep some sites referenced here but also will try to write down some of what I’m learning.

Ruby Warrior is a cool little game that has increasingly difficult levels that require you to write code to have your knight work his way through a dungeon.  If you’ve never learned any coding or Ruby, this probably isn’t the place to start as there really isn’t any teaching.  I’ve been able to fumble my way through the first six levels so far with just a bit of youtube help.  If anything it is learning through watching other people succeed and copying what they are doing.  Not sure if it will be super helpful with my end goal, but it is a fun way to remember certain aspects of Ruby.

Other sites to eventually check out:
Udemy – offering $200 courses for $10 this week
The Odin Project
Thoughtbot – Upcase – recommended by my brother

Gaming Profile

As you probably know, I enjoy board games.  I own an unhealthy amount of games (more than I can play), but whenever someone wants to play a board game, I’m interested.  So when I came across this survey, my brain’s synapses fired.   Board games plus data?  Yes, please.  I didn’t necessarily find out a lot about myself that I didn’t know, but it was interesting to see it graphed.

My Gaming Profile

My game profile told me that I like low conflict, grounded, and independent games.  I didn’t think I prefer as much social manipulation as the chart showed, but I’m usually a non-confrontational sort of person so the low conflict made sense to me.  The really interesting thing was after answering the questionnaire and then entering the last 3 games I enjoyed playing, it recommended 10 games for me to play.  Out of the 10 chosen, I own 6 (and enjoy them), my brother owns 1 (and it is one of my favorites), I’ve played and enjoyed another one but don’t normally have enough people to play with, and the last 2 I’ve been interested in getting.   Not bad, game recommendation machine!  🙂

Clear Glue? Easy!

bottle of glue with glue dot

When I was a kid, I used to put a drop of Elmer’s glue on my desk and let it slowly spread into a perfect circle to dry.  The translucent rubbery circle was fun to pull and stretch until it wore out, which didn’t take too long.  I’d then put out a bunch more drops, some bigger, some smaller, guessing how long the different sizes would take before they’d be ready for play.

Nowadays, Translucent Glue Dots aren’t the rage they used to be.   We now live in the Slime Era.  Rainbow slime.  Water slime.  Butter slime.  Sparkle slime.  There are more kinds of slimes then colors of crayons.  The key to slime is good ‘ole Elmer’s glue.  Now if you want to make clear slime, you can’t use regular Elmer’s glue.  You have to get clear Elmer’s glue.  Hold on, what?!?!  I had no idea there was such a thing as clear Elmer’s glue!

Since my wife is such a good mom, she happened to buy a gallon of the clear stuff for Bug for Christmas.  To keep Bug from randomly finding it in the house, she kept it in the trunk of our brand new car.   And being the good aunt that she is, she also happened to find a balance bike for her niece and nephew who are learning to ride.  This too was stored in the trunk as we are planning on seeing them soon.  Let’s just skip ahead to the inevitable phone call.

Me: Hello?

Wife: Hi.  So… I bought Bug some glue.  And I bought a balance bike.  And I kept them both in the trunk.  Long story short, I was driving around and when I went to put groceries in the trunk, the glue had somehow popped open and it is all over the trunk.  Good news, it is the clear kind.  Bad news, over half of it poured out.

Me: Wow.

Wife: Any ideas of how to get it out of the trunk?

Me: Nope.

Wife: Alright.  Well, I’m going to be working on that until you get home.

Me: Okay, see you soon!

We spent a lot of time getting the glue out of the trunk that afternoon/night, but by the end it looked brand new.  Just in case you ever run into the same situation yourself, the secret is to scrape up the glue using a credit card and then to wash the trunk out with soapy water.  If you were curious, scraping 3/4 of a gallon of glue, one credit card at a time, takes a while…