In the autumn of 2019, I decided to earn a broader understanding of the main features Ruby on Rails provides.
I'm inherently wary of building inert knowledge, and all-too-familiar with transfer of learning's thorniness.
As such, I set out an experiment: I'd (build a slightly-more-complex-than-CRUD app) in parallel to (reading through and, as appropriate, Ankifying the official Rails Guides).
I eventually settled on writing an app through which I could (manage and routinely email myself) quotes from a thousand-record plaintext file I'd been lackadaisically populating since my late... teens...
Shortly into the project, I realized two things:
-
[auth, full-text search, and frontend asset-management] would just never come easy to me w/o deliberate engagement; and
-
those RailsGuides are hefty: lot of content in there!
As such, I expanded my initial "MVC and a bit more" app-blueprint to include each of those fields, too (and, I'd hoped, better balance the coding-to-notetaking ratio.)
I'm writing this in early late January 2020, and by my private roadmap I'm maybe 2/3 of the way done. 😅 Hey, that went better than expected! Feature-complete(ish) is running on Heroku here. Just ping me if you want to access it as a user/manage daily emails: signup is currently disabled because, hey, toy-app budget.
I've got a couple posts, mostly detailing my cost-benefit decisions on handrolling certain aspects vs incorporating specific gems, up at ye olde miniblog. Otherwise, should you want to play around on a copy of your own, read on...
- Install Ruby 2.6.7 and PostgreSQL 12
- There's probably some leeway with the PostgreSQL version, but Heroku and Bundler, at least, certainly won't like other versions of Ruby unless tell them to.
- I recommend grabbing Homebrew, then running
brew install rbenvrbenv initrbenv install 2.6.5brew install postgresqlbrew services start postgresql
- We deliberately want to install foreman outside the app's bundle -- run
gem install foreman - Pull from GitHub with that beautiful green
Clone or downloadbutton above cdinto the directory;bundle installandyarn installrails db:prepare-- this is Rails 6, baby; we can get idempotent!- Possibly both
bundle exec rails webpacker:installthenyarn install, but likely just the latter: try it first - Set up db extensions:
psql opl_development, then (from within the db client) run:opl_development=# select * from pg_available_extensions;opl_development=# CREATE EXTENSION pgcrypto;
- Create at least one admin account, via e.g.
rails cirb(main):001:0> User.create!(name: 'Whatever', email: '[email protected]', password: 'my_arbitrary_password', password_confirmation: 'my_arbitrary_password', admin: true, activated: true)in console to create admin
- Finally, run
foreman startto spin up your local version, and navigate tohttp://localhost:5000/! - NB if you encounter a
No such file or directory @ rb_sysopen - tmp/pids/server.pid (Errno::ENOENT), then either- Run
rails sonce (and, upon hittinglocalhost:3000, exit) or - Manually
mkdir tmp/pids.
- Run
heroku creategit push heroku masterheroku run rake db:migrate- heroku addons:
heroku addons:create sendgrid:starterheroku addons:create scheduler:standard
- Set
hostinproduction.rbto your own Heroku site - If you want others to sign up to your site, set
allow_signupsinproduction.rbtotrue(note this *could* make it possible for you to exceed your free-tier limits, especially given the SendGrid add-on's ceiling of 400 emails/month.) - Finally, in the Heroku Scheduler dashboard...
- If you want to actually receive a daily quote by email, set
rake send_qotd_emailto run sometime in the wee hours of the AM (careful with UTC offset; this may end up being like 9AM by scheduler-time if you're in e.g. CST/CDT) - If you plan to add new quotes and would like them to be added in semi-randomized sequence to that email queue, set
rake populate_send_at_date_for_quotes(also likely best early in the AM, with the same UTC-offset caveat as above.) - If you set either of the above daily jobs, also set
curl #{my_heroku_app_url}to run ~30 min afterrake send_qotd_email, to wake up the web dyno (and, by extension, its follower worker dyno... which will then pick up any newly-queued jobs.)
- If you want to actually receive a daily quote by email, set
-
Checkout the
docker-demobranch -
Add the following keys to
config/database.yml:default: &default # ... host: <%= ENV['POSTGRES_HOST'] %> database: <%= ENV['POSTGRES_NAME'] %> port: <%= ENV['POSTGRES_PORT'] || 5432 %> username: <%= ENV['POSTGRES_USER'] %> password: <%= ENV['POSTGRES_PASSWORD'] %>
-
Create a top-level
.envfile, and add:POSTGRES_HOST=database POSTGRES_NAME=opl_development POSTGRES_USER=#{whatever_you_want} POSTGRES_PASSWORD=#{whatever_you_want} RAILS_ENV=development -
docker-compose build -
docker-compose up -
docker-compose run web rails db:prepare -
Navigate over to
localhost:3000!
Note that, if you (like me) are developing on a mid-2010's MacBook Air, this version will run significantly slower than the above native build. But hey, I had to know that I could convert it over...