||10 months ago|
|app||11 months ago|
|bin||10 months ago|
|config||11 months ago|
|lib||11 months ago|
|semaphore||11 months ago|
|test||11 months ago|
|Gemfile.tt||11 months ago|
|LICENSE||11 months ago|
|Procfile||11 months ago|
|README.md||11 months ago|
|README.md.tt||11 months ago|
|Rakefile.rb||11 months ago|
|config.ru.rb||11 months ago|
|docker-compose.yml||11 months ago|
|editorconfig||11 months ago|
|eslintrc.js||11 months ago|
|example.env.tt||11 months ago|
|overcommit.yml||11 months ago|
|package.json||11 months ago|
|prettierrc.js||11 months ago|
|rubocop.yml.tt||11 months ago|
|ruby-version.tt||11 months ago|
|stylelintrc.js||11 months ago|
|template.rb||10 months ago|
This is a fork
This is based on the excellent work from https://github.com/mattbrictson/rails-template and aimed at working with Rails 7 projects.
For older versions of Rails, please refer to the original repository and use these branches:
These will give you a good head start albeit with some different choices for some parts.
What it is
This is the application template that I recommend for Rails 7 projects. I've assembled this template over the years to include best-practices, tweaks, documentation, and personal preferences, while still generally adhering to the "Rails way".
This template currently works with:
- Rails 7.0.x
- Bundler 2.x
If you need help setting up a Ruby development environment, check out my Rails OS X Setup Guide.
To make this the default Rails application template on your system, create a
~/.railsrc file with these contents:
-d postgresql -m https://git.imfiny.com/OpenSource/rails-templates/raw/branch/trunk/lite/template.rb
This template assumes you will store your project in a remote git repository (e.g. GitHub) and that you will deploy to a production environment. It will prompt you for this information in order to pre-configure your app, so be ready to provide:
- The git URL of your (freshly created and empty) GitHub repository
- The hostname of your production server
To generate a Rails application using this template, pass the
-m option to
rails new, like this:
rails new blog \ -d postgresql \ -m https://git.imfiny.com/OpenSource/rails-templates/raw/branch/trunk/lite/template.rb
Remember that options must go after the name of the application. The only database supported by this template is
If you’ve installed this template as your default (using
~/.railsrc as described above), then all you have to do is run:
rails new blog
What does it do?
The template will perform the following steps:
- Generate your application files and directories
- Create the development and test databases
- Commit everything to git
- Push the project to the remote git repository you specified
What is included?
Optional support for
rails new command to get started with Vite! [Vite][vite] is an easy to use alternative to Webpack(er), and much more powerful than the standard import map and css/jsbundling-rails options that are built into Rails.
- Frontend code (JS, CSS, images) will be placed in
yarn startto start the development server with hot reloading
- SCSS will be used for styles (the
--cssoption will be ignored)
If you don't specify
These gems are added to the standard Rails stack
- active_type – for building simple and effective form/service objects
- sidekiq – Redis-based job queue implementation for Active Job
- dotenv – for local configuration
- [Bulma] - a nice, simple yet powerful css framework
- annotate – auto-generates schema documentation
- amazing_print – try
- rubocop – enforces Ruby code style
- [flay] - dig deeper into code style and code structure
- brakeman and bundler-audit – detect security vulnerabilities
- [rspec] – A good basis for tests.
I like to use Postmark for transactional email, and so I've included the postmark-rails gem and configured it in
environments/production.rb. Make sure to sign up for a Postmark account to get an API key, or switch to your own preferred email provider before deploying your app.
Other tweaks that patch over some Rails shortcomings
- A much-improved
- Log rotation so that development and test Rails logs don’t grow out of control
How does it work?
This project works by hooking into the standard Rails application templates system, with some caveats. The entry point is the template.rb file in the root of this repository.
Normally, Rails only allows a single file to be specified as an application template (i.e. using the
-m <URL> option). To work around this limitation, the first step this template performs is a
git clone of the
mattbrictson/rails-template repository to a local temporary directory.
This temporary directory is then added to the
source_paths of the Rails generator system, allowing all of its ERb templates and files to be referenced when the application template script is evaluated.
Rails generators are very lightly documented; what you’ll find is that most of the heavy lifting is done by Thor. The most common methods used by this template are Thor’s
gsub_file. You can dig into the well-organized and well-documented Thor source code to learn more.