Rails Generators - App Creation

I have recently been getting back into some Rails development so I’ve decided to make a short series of reference blogs on common generators.

Note: you can list Rails generators with the following command.

rails -h 

To the right, you will have a basic explanation of what each flag does, however, it is my hope through this blog I can provide a little more context on independent use cases.

One important thing to note about this helper’s flags is you have the ability to selectively exclude items. For example, looking at the screenshot below we could independently exclude TurboLinks with --skip-turbolinks however if we included the -J flag when generating our app it will exclude TurboLinks, JavaScript, and Jbuilder collectively as they are sub-items.

Screen shot of focused code
Screen shot of focused code

Generating a new app

rails new app-name Creates a rails app with default configurations (a SQLite3 database and so on) it is at this stage you will name your app (opposed to app-name you could call it something like "my-cool-blog")

Generating a new app with a database of your choice

rails new app-name --database=postgresqlUtilizing the database flag you can set the Rails configuration to use a database of your choice. The above example is for configuration with Postgresql, a popular and recommended choice for many. Other options include MySQL, SQLite and so on. 

Generating a new app from a template

From a local file
rails new app-name -m ~/my-local-template.rb
From a URL
rails new blog -m http://example.com/template.rb
Rails gives you the option to generate your app from an existing template, templates can either be located on your computer or retrieved from a web address. Templates are essentially pre-configuration and may automate tasks such as setting API keys, adding custom Gems, or network authorization. For information on how to make your own template, the Rails website has an informative guide here.

Excluding Rails Default Test Framework

From a local file
rails new app-name -T
By default Rails includes its own testing framework, however, it is a common preference of Rails developers to use alternatives such as RSpec or Cucumber. If you do not wish to use the default testing including this flag will help alleviate your app from being cluttered with unneeded files.

Excluding The Front End For API Only Apps

From a local file
rails new app-name --api
In some use cases, you may only need to use Rails to serve information as an API. Running your app generator with this flag will completely exclude the front-end portion of the application. This is particularly useful when you want to build your front end in a javascript framework such as VueJS or React.

Hi, I’m Steven, most call me Steve! I’m a programmer, musician, and artist. This blog contains various tutorials and posts related to software development.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store