Skip to content

Basic Setup

Matt Taylor edited this page Feb 22, 2024 · 2 revisions

Setup

RailsBase Config file

RailsBase needs some basic configuration to function. The following configuration file is needed for the insane amount of customization that RailsBase offers (List of Configurable options)

# config/initializers/rails_base_config.rb
RailsBase.configure do |config|
  # Rails base is filled with some sane defaults.
  # This file is not necesary and can also be used with ENV variables
end

Email Setup

Email is a requirment for authenticaiton with RailsBase. Google Mail offers a free option to mail from any account.

Add the following to the rails base configuration:

# config/initializers/rails_base_config.rb
RailsBase.configure do |config|
  # ...
  config.mailer.from = '<user_name>'
  config.mailer.password = '<app_password>'
  # ...
end

MFA/2FA setup

MFA/2FA is enabled with Twilio and an account with Twilio account is required. Twilio Sign up Please note that twilio has a test credentials that do not require you to spend credits sending a text message

# config/initializers/rails_base_config.rb
RailsBase.configure do |config|
  # ...
  config.mfa.twilio_sid = '<twilio_sid>'
  config.mfa.twilio_auth_token = '<twilio_auth_token>'
  config.mfa.twilio_from_number = '<twilio from number>'
  # ...
end

When MFA is not desired or do not want to pay for Twilio

MFA and 2FA can is not a requirement, but it must be turned off explicitly. To turn this feature off add the following to the configuration:

# config/initializers/rails_base_config.rb
RailsBase.configure do |config|
  # ...
  config.mfa.enable = false
  # ...
end

Basic Configuration File

# config/initializers/rails_base_config.rb
RailsBase.configure do |config|
  config.mailer.from = '<user_name>'
  config.mailer.password = '<app_password>'
  config.mfa.twilio_sid = '<twilio_sid>'
  config.mfa.twilio_auth_token = '<twilio_auth_token>'
  config.mfa.twilio_from_number = '<twilio from number>'
end

Controller Setup

When a new project starts, the controllers will be initialized like the following:

# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
end
# BAD

We don't want our application controller initialized like this. We want it to looke like the following:

# app/controllers/application_controller.rb
class ApplicationController < RailsBase::ApplicationController
end
# Good!!

This will inherit from RailsBase::ApplicationController where the controllers main lgoic is shared from.

Routes Setup

In the main application routes folder, mount the the RailsBase Engine routes.

# config/routes.rb
Rails.application.routes.draw do
  mount RailsBase::Engine => '/'
  #
  # The rest of your applications routes
  #
end

View the Dummy Application routes for how the routes should look.

Database Setup

RailsBase provides a User Migration, ShortLivedData Migration, Secrets Migration, and AdminAction Migration. These allow the basic functionality and must be run priort to booting a project with RailsBase for the first time.

In bash console ensure the following is run:

bin/rails db:migrate

Thats all their is!

At this point you should be able start your server and run the application. You can seed the DB with a basic User or create a user yourself by signing up!

bin/rails s