A Guide to Using Ruby on Rails Application Templates
Tags: rails, ruby, showdev, tutorial
Published: 2019-02-14 04:49:17


{% youtube kuKMRl8nj2w %}


As my experience with Ruby on Rails continues to grow I explore more and more by hitting the ground running with a base application template for new projects. In this guide, I'll discuss how I created my most recent rails application template as well as what all get's included.

Ruby on Rails is by far the quickest path to a production worthy application that I know of. You can generate an entire blog in as little as 5 minutes using the built-in CLI. With that in mind, and my constant effort to provide tutorials around the framework, I took to building an application template for use going forward. 

My Let's Build: With Ruby on Rails series has been a foundation for my learning of the framework. After several builds, I began to notice a lot of patterns involved in the way I needed to configure a new app each time I ran `rails new`. 

Due to the nature of the tutorials, I wanted to provide "an approach from scratch" because many tutorials out there assume you know a lot before beginning. I still believe in this principle because practice makes perfect but in my particular case, I bypass a lot of the rudimentary configuration making use of an application template. 

With an application template you can create a new Rails app and define preconfigured decisions based on what you find you use the most in your past/current projects. Assuming you need to use a template, this can be a huge time saver.

This might not be for you if you really don't build a large number of apps but could prove worthy if you have ideas that you eventually want to build and don't want to waste time configuring the app every time you kick something off. 


### What is a Ruby on Rails application template?

> Application templates are simple Ruby files containing DSL for adding gems/initializers etc. to your freshly created Rails project or an existing Rails project.

In short, it's a way to install your favorite gems, configure your app, and even version control your project using one command.


### How do I use the template?

If you're new to Ruby on Rails I invite you to check out my series so far linked at the bottom of this post. If you have some familiarity with the framework you may know by now that creating a new app is as simple as running `rails new my_app`. 

Passing the template through works like this

```bash
$ rails new my_app -m template.rb
```

Here our CLI will look for a file called `template.rb` to guide it while it installs a new app. 

You can [download the latest template](https://github.com/justalever/kickoff_tailwind) I created using [Tailwind CSS](https://tailwindcss.com/) out of the box. I called it `kickoff_tailwind`. 

Download a copy of that and `cd` within the folder. There you can create your app by passing the `template.rb` file through as I stated before.

From there your app will scaffold and you can move the app folder wherever you like on your system.

### What comes with it?

The included gems are:

- [devise](https://github.com/plataformatec/devise)
- [friendly_id](https://github.com/norman/friendly_id)
- [foreman](https://github.com/ddollar/foreman)
- [sidekiq](https://github.com/mperham/sidekiq)
- [tailwindcss](https://github.com/IcaliaLabs/tailwindcss-rails)
- [webpacker](https://github.com/rails/webpacker)


- Webpack support + Tailwind CSS configured in the `app/javascript` directory.
- Devise with a new username and name field already migrated in. Enhanced views using Tailwind CSS.
- Support for Friendly IDs thanks to the handy friendly_id gem. Note that you'll still need to do some work inside your models for this to work. This template installs the gem and runs the associated generator.
- Foreman support thanks to a Profile. Once you scaffold the template, run `foreman start` to initialize and head to `locahost:5000` to get `rails server`, `sidekiq` and `webpack-dev-server` running all in one terminal instance. Note: Webpack will still compile down with just rails server if you don't want to use Foreman.
- A custom scaffold view template when generating theme resources (Work in progress).
- Git initialization out of the box


#### More Templates

- [Kickoff - Tailwind](https://github.com/justalever/kickoff_tailwind)

- [Kickoff - Bulma](https://github.com/justalever/kickoff)

- [Jumpstart - Bootstrap](https://github.com/excid3/jumpstart) - Chris Oliver from [gorails.com](https://gorails.com) - A hugh inspiration for Kickoff

## Shameless plugs 

If you liked this post, I have many more builds on [YouTube](https://youtube.com/c/webcrunch) and my [blog](https://web-crunch.com). I plan to start authoring more here as well. Want more content like this in your inbox? [Subscribe to my newsletter](https://web-crunch.com/subcribe) and get it automatically.

<a href="https://hellorails.io" target="_blank">
![](https://thepracticaldev.s3.amazonaws.com/i/wkb5yyst7pxa1s16kr2u.jpg)
</a>
☝ Want to learn Ruby on Rails from the ground up? Check out my upcoming course called [Hello Rails](https://hellorails.io)