Ruby on Rails app that finds viable routes for the CHIditarod, based on customizable criteria like leg length, overall race length, etc.
| Variable Name | Purpose |
|---|---|
GOOGLE_API_KEY |
Google Cloud Platform API key with access to the APIs listed below. |
MOCK_MAP |
When true, use mock data instead of calling Google APIs. Useful for local development without an API key. |
Your Google Cloud Platform account and associated API key must have access to the following APIs:
Tested on macOS Sequoia 15.1.1.
brew install rbenv
rbenv install $(cat .ruby-version)
gem install bundlerbrew install libffi libpq
bundle config --local build.ffi --with-ldflags="-L/opt/homebrew/opt/libffi/lib"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/homebrew/opt/libffi/lib/pkgconfig"
bundle config --local build.pg --with-opt-dir="/opt/homebrew/opt/libpq"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/homebrew/opt/libpq/lib/pkgconfig"
bundle installcd frontend && npm installStart the PostgreSQL container and set up the database:
docker compose up -d db
bundle exec rails db:create db:migrate
bundle exec rake db:seed # optional: seeds sample locationsYou need two processes running — the Rails API server and the Vite dev server.
Without a Google API key (mock mode):
MOCK_MAP=true bundle exec rails serverWith a real Google API key:
GOOGLE_API_KEY=your-key-here bundle exec rails serverRails starts on http://localhost:3000.
cd frontend && npm run devVite starts on http://localhost:5173 and proxies /api requests to Rails.
Navigate to http://localhost:5173 in your browser.
bundle exec rspeccd e2e && npx playwright test --reporter=listTests are organized into two projects:
- seeded (
tests/seeded/) — Tests that reset + seed the DB before each test - fresh (
tests/fresh/) — Tests that reset the DB and create their own data
DB management is handled automatically per-test via fixtures. No manual seeding/cleaning needed.
cd e2e && npx playwright test --project=seeded # run only seeded tests
cd e2e && npx playwright test --project=fresh # run only fresh testscd frontend && npm run buildThe web UI handles all of the below, but you can also use the Rails console directly.
bundle exec rake db:seed
GOOGLE_API_KEY=... bundle exec rails cBulkLegCreator.perform_now(Location.pluck(:id))RouteGenerator.call(Race.first)
winners = Route.complete
puts winners.map(&:to_csv)
puts winners.map(&:to_s)
selected = winners.select { |r| r.name != nil }
selected.map(&:to_csv)GeocodeLocationJob.perform_now(Location.pluck(:id))After selecting and naming routes, generate maps via the Google Maps API:
names = [
[771,"A"],[778,"H"],[806,"J"],[809,"K"],[816,"L"],[890,"G"],
[931,"I"],[991,"D"],[1013,"B"],[1051,"C"],[1058,"E"],[1134,"F"]
]
names.each do |n|
r = Route.find(n[0])
r.update!(name: n[1])
puts "Route ID #{r.id} now has name #{r.name}"
endThen visit routes in the browser:
http://localhost:3000/races/3/routes/771
Race.destroy_all; Route.destroy_all; Leg.destroy_all; Location.destroy_all; nil