Blog

How to Install Ruby on Rails on a MacBook Pro 2021

This post describes how to install Ruby on Rails on a MacBook Pro.

It’s nice that 2021 MacBook Pros come with the Ruby programming language installed by default. That’s great! There is a problem though because the Ruby version installed by default is 2.6.8, which is just shy of what we need to write a Ruby on Rails v7.0.3.1 application.

To fix this problem, we need to install a more recent version of Ruby on Rails. At the time of writing this, the most recent stable version was Ruby 3.1.0. To do that, I propose that we install a version management software called Ruby Version Manager (RVMOn Github).

In order to install RVM, they say you need to install GPG keys. So I copy the gpg command over to the terminal and we learn that we don’t have the command installed on the new MacBook. Ok, so now we need to find out how to install gpg onto our machine.

To install gpg, I’m going to use a popular package managing software called Homebrew (https://brew.sh/). I followed the Homebrew installation documentation and it worked as it was supposed to.

  • Once we install Homebrew we will be able to install gpg2.
  • Once we install gpg2 we will be able to install RVM.
  • Once we install RVM, we will be able upgrade our Ruby version.
  • Once we upgrade our Ruby version, we will be able to install Rails.
  • Once we install Ruby on Rails, we will accomplish the mission.

When you’re struggling with installing software on the command line, don’t forget to try closing your terminal and reopening it.

Finally, we create a new Ruby on Rails application on the Desktop folder of our application.

With the Ruby on Rails application running via our terminal, we open a web browsing tool (Brave, Google Chrome, Safari, etc.) and navigate to the default port (localhost:3000). Huzzah! We have a Ruby on Rails application running locally.


Ruby on Rails Installation Softwares Used:

  • Terminal
  • Better Snap Tool
  • Ruby
  • Rails

Commands Used for Ruby on Rails Installation on Macbook:

  • ruby -v
  • rails -v
  • sudo gem install rails
  • gpg2 –revc-keys
  • brew help
  • brew install gnupg
  • rvm help
  • rvm install 3.1.0
  • rails new first_m1_rails_app
  • cd first_m1_app
  • rails server

2021 Macbook Pro Details:

  • Operating System: macOS Monterey
  • Machine: MacBook Pro (16-inch, 2021)
  • Chip: Apple M1 Pro
  • Memory: 16 GB

A Simple Vanilla Ruby way to Benchmark Test your Code for Speed

In this example, I wanted to know speed differences between the .uniq and .to_set speed. Here’s a simple way to measure computational complexity:

# any_file_name.rb
require 'benchmark'
require 'set'

data = [
  { id: 1, color: "brown", status: "closed" },
  { id: 2, color: "yellow", status: "open" },
  { id: 3, color: "brown", status: "closed" },
  { id: 4, color: "brown", status: "open" },
  { id: 5, color: "red", status: "closed" },
  { id: 6, color: "blue", status: "open" },
  { id: 7, color: "green", status: "closed" },
  { id: 8, color: "green", status: "open" },
  { id: 9, color: "brown", status: "closed" },
  { id: 10, color: "red", status: "open" },
  { id: 11, color: "blue", status: "closed" },
  { id: 12, color: "yellow", status: "open" },
  { id: 13, color: "green", status: "open" },
  { id: 14, color: "yellow", status: "open" },
  { id: 15, color: "blue", status: "closed" },
  { id: 16, color: "blue", status: "closed" },
  { id: 17, color: "blue", status: "closed" },
  { id: 18, color: "green", status: "open" },
  { id: 19, color: "yellow", status: "open" },
  { id: 20, color: "brown", status: "closed" },
  { id: 21, color: "green", status: "closed" },
  { id: 22, color: "red", status: "closed" },
  { id: 23, color: "red", status: "open" },
  { id: 24, color: "red", status: "open" },
];

uniq_start = Time.now
data.uniq{ |x| x[:color] = "red" }
uniq_finish = Time.now
uniq_diff = uniq_finish - uniq_start

p (uniq_diff * 1_000_000).to_s # evaluates to something like 7.0

set_start = Time.now
data.to_set{ |x| x[:color] = "red" }
set_finish = Time.now
set_diff = set_finish - set_start

p (set_diff * 1_000_000).to_s # evaluates to something like 32.0

In the above code we assign variables to the start and end of each function. Then we run the methods and we finally print out the difference times a million so we get the millisecond computational complexity.

How to Register an Ethereum Name Service (ENS)

This post covers how to register an ethereum name service (ENS).

Most people are aware of how to register a Domain Name Service (DNS). If you’ve ever registered a domain, like usefulprogrammer.org, then you have utilized the DNS system. Anyone who has a .com or a .net website has registered a site with a DNS.

The ENS is registering a name server with the Ethereum blockchain. Let’s see how to do it…

How to Register your Ethereum Name Service

Step 1:

 

 

 

…the impediment to action advances action…

Reset Password Forwarding to Root Domain – Deploying a Ruby on Rails app + Heroku and Devise Gem

Today I solved an error in my Ruby on Rails application.

The problem was that the reset password process led to the root path, rather than the reset password Devise view. This was an error in the production version of the application, which is deployed on Heroku, and NOT on my local development version.

My problem was solved by adjusting the config/environments/production.rb file.

I had this:

config.action_mailer.default_url_options = { host: 'windaily.app' }

Which needed to be set to this:

config.action_mailer.default_url_options = { host: 'https://www.windaily.app' }

This was a bit of a tough one to figure out because I wasn’t getting any error messages. It just didn’t work.

But now the production app is working with the Devise :recoverable setting implemented.

SemaphoreCI Fails With Node Version Due to ExecJS Dependency – BUG FIX

I came across this issue while upgrading an older version of a Ruby on Rails app. The error caused my continuous integration to fail.

ActionView::Template::Error (Autoprefixer doesn’t support Node v0.10.48. Update it.)

The way I solved it was to re-initialize the Node object in the application.js file.

module AppName
  ... # removed for brevity
end

## TODO: Check to see if ExecJS has fixed this bug. If so, delete the code below and check SemaphoreCI
module ExecJS
  module Runtimes
    Node = ExternalRuntime.new(
      name:        "Node.js (V8)",
      command:     ["node", "nodejs"],
      runner_path: ExecJS.root + "/support/node_runner.js",
      encoding:    'UTF-8'
    )
  end
end

This is a hackey way to solve this problem. With luck, ExecJS will update their gem in the future and this code can be removed. I’ve added a TODO here so I can remember to fix this down the line (note: if you run rails notes, you can see a list of TODOs in your app.)

Set up a Template Engine – Advanced Node and Express – Quality Assurance Certification FreeCodeCamp

In this tutorial we set up a template engine called Pug. This is one part of many making up the Advanced Node and Express section. This section makes up part of the Quality Assurance Certification. I want to say a big thank you to FreeCodeCamp (www.freecodecamp.org) for the curriculum. My goal with these videos is to support early stage programmers. I hope that these videos help you to learn faster and understand more fully. For me, learning this was difficult so I hope this makes your life less difficult. Thank you for watching.

The whole playlist for Advanced Node and Express can be found here:

https://www.youtube.com/playlist?list=PL3vpzVxKa3PjW360acemH5PDZ73-1Q_Pd

Posted in Uncategorized

Exercise Tracker PART 1 – APIs and Microservices – Free Code Camp

In this APIs and microservices project, we do part one of building an exercise tracker API. This is the fourth part of four sections where we work to achieve our APIs and Microservices Certification. This video constitutes one part of many where I cover the FreeCodeCamp (www.freecodecamp.org) curriculum. My goal with these videos is to support early stage programmers to learn more quickly and understand the coursework more deeply. Enjoy!

The whole playlist for APIs and microservices certification can be found here:

Exercise Tracker, APIs and Microservices, part one, part I

Posted in Uncategorized