/rails7template

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

Primary LanguageRuby

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.

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