A Whole New "Hello, World"

I'm writing my first-ever Rails app on my own and I'm apparently foolhardy enough to write about the progress as I go. I've made a functional app in Rails before by following along with the great Lynda course Ruby on Rails 5 Essential Training. This is the first time I'm flying solo.

First thing I'm going to do is create my new Rails app:

rails new memeory -d mysql

The app I've decided to build is going to be for collecting all of the stupid gifs and other memes my friends and I share with each other. That way, if we ever want to reference one again, we'll have one handy place to get to it all. Plus, free opportunity to pun right there in the app name.

I've gotta admit, I was a little stuck here. The question of "where to go next" is so vast, I floundered for a bit. I decided, after a while, that the first thing I'd do is set up a public area and the route to it.

rails generate controller Public index show

This gives me a new controller called Public that has two default actions (and views) - index and show. Index will serve as the general homepage where, at least right now, I picture a list of recently submitted memes (that weren't marked as private) can be displayed. The show action and view will display details on a specific one.

With that in mind, I added that index as the root route.

root 'public#index'

That quick line goes in 'app/config/routes.rb'. Now whenever someone visits the root URL, it'll direct to the index action of the public controller.

I booted up the server and browsed to localhost:3000 in Chrome ... and immediately met my first error.

Truthfully, this screenshot isn't the first error I encountered. At first it gave me the same error for user 'root'@'localhost'.

Then I had to refresh myself a bit on just how to use MySQL. The new Rails app command above specified to use MySQL as the database instead of the normal SQLite. It's just what I learned in the Lynda course and I didn't want to overcomplicate it for myself if I didn't have to.

So I went into MySQL and created the database and granted access for my user:

CREATE DATABASE memeory_development;
GRANT ALL PRIVILEGES ON memeory_development.* TO 'memeory_db'@'localhost' 
IDENTIFIED BY 'password';

Now obviously that wasn't my password, but I can't reveal all my secrets, which brings me to the next step: keeping that password a secret while still getting to use all the lovely features of GitHub. This was something the Lynda course didn't cover, so I had to figure that out on my own.

Some Google-fu led me to ENV variables. On my macOS machine, I can run this:

export MEMEORY_DEV_PASSWORD=password

in terminal and then add this line to my database.yml file:


to keep that password free from prying eyes. It does mean that any other computer I attempt to run this Rails app on will have to have a value for DEV_DB_PASSWORD, or I'll likely meet another error.

As an added bonus, I edited ~/.bash_profile to include this export line, so I won't have to create the environment variable every time I reboot.

With all of that work, I have the home page working properly. Expect another post soon with next steps.