Skip to content

A Dockerized Rails 7 fully-featured template application with opt-in authentication support

Notifications You must be signed in to change notification settings

Shannarra/rails7template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rails 7 Template application Ruby

This app demonstrates Rails 7 with PostgreSQL, import maps, turbo, stimulus, bootstrap and hotwire, all running in Docker.
You can also bootstrap the application with authentication frameworks like Devise in order to ease your work.

Features

  • Rails 7
  • Ruby 3
  • Bootstrap
  • Dockerfile and Docker Compose configuration
  • PostgreSQL database
  • Redis
  • GitHub Actions for
  • Dependabot for automated updates

Optional features:

Requirements

Please ensure you are using Docker Compose V2. This project relies on the docker compose command, not the previous docker-compose standalone program.

https://docs.docker.com/compose/#compose-v2-and-the-new-docker-compose-command

Check your docker compose version with:

$ docker compose version
Docker Compose version v2.20.2

Initial setup

You can just run the startup.sh script:

sh ./startup.sh

This will bootstrap a Rails 7 application that has some sample data but misses a lot of features, for example, it has no authentication.

If you want to have built-in authentication with Devise you can do the following:

Devise setup

(optional)
Setting the application up to work with Devise is very straightforward, just a single command:
sh startup.sh --devise user

In this case, the application will be created with authentication mechanism for a model called "User".
The given model will be created, migrated and integrated with the application upon startup.

Debugging

If you have already ran the startup.sh script in your project for a devise, and try to run it again with the SAME devise, you WILL encounter the following error:
PG::DuplicateColumn: ERROR:  column "email" of relation "[DEVISE NAME]" already exists (PG::DuplicateColumn)

Followed by an UI error saying that

You have 1 pending migration:

db/migrate/YYYYMMDDHHMMSS_add_devise_to_[DEVISE NAME].rb

To resolve this issue, you need to either:

  • drop and remove the entire container, and run the startup script again
    or
  • manually remove the new migration causing the issue and re-run the script with a changed devise name.

Extras

Using the startup.sh script, you can skip the next step and make it so the application starts immediately after it has been built:

sh startup.sh --run # -r works as well :) 

If you want to learn more about this script you can just call the --help option.

Running the Rails app

docker compose up

Then just navigate to http://localhost:3000

Running the Rails console

When the app is already running with docker-compose up, attach to the container:

docker compose exec web bin/rails c

When no container running yet, start up a new one:

docker compose run --rm web bin/rails c

Running tests

docker compose run --rm web bin/rspec

Time localization

If you want to change the timezone to your specific locale you can do this very simply, just change the TIMEZONE variable in the .env file:

# TODO: change to CET, EET or wherever you live
TIMEZONE=UTC

Updating gems

docker compose run --rm web bundle
docker compose up --build

Production build

docker build -f production.Dockerfile .

Deployment

This app can be hosted wherever Ruby is supported and PostgreSQL databases can be provisioned.

Render

Deploy to Render

NOTE: You will need to generate a production secret with bin/rails secret and set it as the SECRET_KEY_BASE environment variable.

Credits/References

Rails with Docker

Rails 7 with importmaps

Rails 7 with hotwire