August 06, 2017 • 1 min read
Not long ago I created a new Ruby on Rails web application using the Rails 5.1.3 release. Our goal was a Rails API supporting a React.js frontend, and it couldn’t have been easier. The Rails team has recognized this important design pattern, and is taking great strides to simplify the setup.
How? With some interesting feature flags. Here are three of my favorites. A few of these surfaced before 5.1.3, but they were all novel and delightful to me.
[--api], [--no-api] # Preconfigure smaller stack for API only apps
According to the documentation, this flag limits the browser-related middleware in your project, makes
ApplicationController inherit from
ActionController::API instead of
ActionController::Base, and configures the generators to skip views, helpers, and assets when you generate a new resource.
react option set us up instantly to work with React.js. Amazing! Almost as easy as using create-react-app.
Thanks to the Rails core team for this forward-thinking release. If complex setup was preventing you from mixing Ruby on Rails with React.js, consider yourself out of excuses. Happy coding!
Blog of Jake Worth.