rails7-template Tailwind Templates

Rails7 Template

A Rails 7 app pre-configured with my go-to setup for starting new apps. Postgres, Devise, Tailwind

README

This is a pre-configured rails 7 app with some additional libraries and config that I prefer as a generic foundation for new apps. Those are:

  • Postgres as my preferred SQL database implementation
  • Devise authentication (which - as of time of writing - is a bit of a trick to get integrated with Rails 7 due to Turbo. I wrote a short article about it here. Anyhow, this setup includes:
    • Sign-in/up/out
    • Email validation
    • Password reset
  • Tailwind UI a utility CSS framework
  • FactoryBot which makes fixturing for tests a whole lot easier
  • Audited which - when enabled for a model - builds a history of each mutation to a database row
  • Annotate which adds comments outlining the schema to models and model tests

Dependencies

  • Ruby version: 3.0.1p64
  • System dependencies: ruby, rails, the foreman gem (installed locally), postgres, node (12+), and yarn must be installed on the system.

Setup

  1. Copy this template, clone it, and download it.
  2. Delete the /config/credentials/.gitignore file. This will allow your encrypted config files to be commited with git. Don't worry: the top-level .gitignore still includes ignoring the test, development, and production keys from the credentials folder!
  3. Run bundle installto install back end dependencies
  4. Create test/dev/production credential files. Without one for each environment you use, you'll get a NoMethodError when executing in that environment because ERB will try to load in a key from it's environment's credentials file. To do this, create a /config/credentials/<environment>.yml.enc file (and key) via EDITOR=nano rails credentials:edit -e <environment>. The final file should look like the following but include your creds. I use sublime, so I run EDITOR="subl --wait" rails credentials:edit -e <environment>. Having a blank instead of your creds will work fine if you don't need creds for that environment:
postgres:
  host: <eg. 127.0.0.1>
  username: <eg. rails_core_developer>
  password: <eg. 1234>
  1. Run rake db:setup to create, migrate, and seed test & dev databases
  2. Run yarn install to install front-end dependencies
  3. (Unix only) Run from the chmod -R u+x bin to change the permissions of executables and prevent getting an access denied error.

Running the server

# Run postgres. Only needs to be run once per restart.
# You can also configure it to run automatically on startup
sudo service postgresql start

# Use Foreman to run the server and recompile CSS/JS
# assets with any changes
bin/dev

# Alternately, to run just the server without being able
# to reload changes to the CSS/JS
rails s

# And if you do need to do a one off recompilation of assets
rails assets:precompile

Running the test suite

bundle exec rspec

Future topics, if relevant

  • Configuration
  • Database creation
  • Database initialization
  • Services (job queues, cache servers, search engines, etc.)
  • Deployment instructions

Top categories

Loading Svelte Themes