Lesson Tuesday

For our final multi-day project, we'll run multiple Rails applications simultaneously. In addition to launching a Rails API application, we’ll also build an application that communicates with our Rails API!

Running Multiple Rails Applications


We can run multiple applications simultaneously as long as we specify different ports for each. If we're using Webrick, the command $ rails s automatically launches the application on http://localhost:3000.

But if we try launching a second application with $ rails s, we'll receive an Address already in use error. This is because http://localhost:3000 is already being used by the first application.

However, we can run $ rails s -p 3001 to specify the second application should run on http://localhost:3001 instead. (You can also choose another port number if you prefer.) This allows you to run multiple Rails applications at the same time.

Creating a Rails Application Without a Database


Your API will almost certainly need a database. However, the Rails application that's communicating with the API might not need one. After all, the whole point is for the API to handle the backend stuff, including database management. For that reason, you can create a Rails application that has no database. To do so, when using the $ rails new command, add the following flag: -O. This instructs Rails to skip ActiveRecord. There's also a more verbose flag that means the same thing as -O: --skip-active-record. While the application will work even if it has an unused database, it's always better not to bloat an application with features we don't need.

Lesson 16 of 19
Last updated more than 3 months ago.