Iamvery

The musings of a nerd


A "rails new" For You

— Feb 17, 2015

Recently, I went on a personal endeavor to determine the best way to create a new Rails app pre-configured to my liking. I was sick and tired of wasting time replacing and configuring test runners, adding development gems I prefer, and reinventing the README. Why did it take so long for me to do this?

.railsrc

For some reason it took me a long time to discover this handy script. Following the convention of other “run configuration” files, you can add options here that you wish to be included every time you rails new.

My config…

  • skips bundle install (handled later)
  • skips .keep files
  • skips spring
  • skips Test::Unit (I prefer RSpec)
  • skips turbolinks
  • users PostgreSQL instead of SQlite

Here it is:

Rails App Template

The command line options can only get me so far. To complete my desired pre-configuration, it’s time to automate the things with Rails application templates.

App templates allow you to define a procedure used to config an app. It has built in hooks for bundler and git. My config…

  • installs preferred gems
  • configures test runner
  • cleans up Gemfile
  • installs bin/bootstrap script
  • adds a reasonable README
  • commits each change separately

Here is the full template:

I keep all my configuration files in a Gist so they can be downloaded as needed.

To make sure the template is always used for new apps, I added an alias to my environment.

Creating a new app is as simple as railsup next_big_thing.

Voila!

This turned out to be a great learning experience. The task wasn’t as daunting as I had imagined it to be. I am always working to improve these things, so keep an eye on my dotfiles if you’re interested.

comments powered by Disqus