Rails Templates
Our templates offer a rich boilerplate to jump start Rails-based application development and are based on our experience with building complex applications over the years.
- Install ruby and set your local ruby version to
3.0.1
- Install rails
7.0.1
- Install node
16.13.2
(For creating web application)
π If running on Apple M1, to build docker image, please make sure to set platform to AMD64 by
export DOCKER_DEFAULT_PLATFORM=linux/amd64
In order to use the template, initialize a new app with the following parameters:
rails new <app_name> -m https://raw.githubusercontent.com/nimblehq/rails-templates/main/template.rb
Supported template options:
--api
- create an api-only application
To apply the template on an existing application, run following rails command:
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/main/template.rb
# To apply on an api application
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/main/template.rb API=true
# To apply a specific addon
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/main/template.rb ADDON=<addon name>
Available Addons:
docker
nginx
phrase_app
semaphore
bootstrap
slim
devise
Read more about Rails Application Template in the official Rails Guides.
.
βββ .template
β βββ addons
β β βββ docker
β β βββ ...
β β βββ template.rb
β βββ variants
β βββ api
β β βββ ...
β β βββ template.rb
β βββ web
β βββ ...
β βββ template.rb
βββ app
βββ bin
βββ config
βββ spec
βββ ...
βββ README.md
βββ README.md.tt
βββ template.rb
We keep the Rails-app-like structure. On the root, there are base project file templates.
Other files including the template options are in .template
folder.
There are 2 kinds of the template options:
-
Variants - For the app main options, which are
web
andapi
. -
Addons - For other extra options that we can add to the project like
docker
orbootstrap
, use the promptask
to generate a question before generating the project.
There are 2 template file types:
-
.tt
filesThis file is used for templating the whole new file. In case if we want to create a new file that Rails does not generated.
-
.rb
filesThis is used for modifying the files that Rails has generated. The file name should be the same as on the generated app. If it is not a ruby file, append the
.rb
as an extension e.g.Gemfile.rb
We are using Serverspec to test the template. For any changes made, you must add a spec for it.
Test files are located under .template/spec
folder
.
βββ ...
βββ .template
β βββ ...
β βββ spec
β β βββ addons
β β β βββ base
β β β β βββ docker
β β β β β βββ ...
β β β β β βββ template_spec.rb
β β β β βββ semaphore
β β β β β βββ ...
β β β β β βββ template_spec.rb
β β β βββ variants
β β β β βββ web
β β β β β βββ boostrap
β β β β β βββ ...
β β β β β βββ template_spec.rb
β β β β βββ api
β β β β β βββ addon
β β β β β βββ ...
β β β β β βββ template_spec.rb
β β βββ base
β β β βββ ...
β β β βββ template_spec.rb
β β βββ variants
β β β βββ web
β β β β βββ ...
β β β β βββ template_spec.rb
β β β βββ api
β β β β βββ ...
β β β β βββ template_spec.rb
When using template string with heredoc, use the proper name following the file type / content.
This provides the meaningful context to the content and some IDEs also support to highlight the content depending on the type.
DOCKERFILE
ERB
HTML
IGNORE
- For any ignore file e.g..gitignore
,.eslintignore
JAVASCRIPT
JSON
PROCFILE
RUBY
SCSS
SHELL
For other files that are not fit the types above, use the extension as the name
e.g. TOOL_VERSION
for .tool-version
file.
For the normal string, name it after the content
e.g. ERROR
for template error message.
To run RuboCop against the template:
.template/bin/rubocop
Any RuboCop command options can be passed:
# Run RuboCop with auto correct
.template/bin/rubocop -a
This project is Copyright (c) 2014 and onwards. It is free software, and may be redistributed under the terms specified in the LICENSE file.
This project is maintained and funded by Nimble.
We love open source and do our part in sharing our work with the community! See our other projects or hire our team to help build your product.