Skip to content

Instantly share code, notes, and snippets.

@keilmillerjr
Last active June 5, 2021 22:03
Show Gist options
  • Save keilmillerjr/d29a2f04ce94cfd7b238b087075c7713 to your computer and use it in GitHub Desktop.
Save keilmillerjr/d29a2f04ce94cfd7b238b087075c7713 to your computer and use it in GitHub Desktop.
Ruby on Rails using asdf (linux & mac)

Ruby on Rails using asdf (linux & mac)

asdf

asdf allows you to manage multiple runtime versions with a single CLI tool. It's an alternative to rvm or rbenv, but isn't limited to just ruby.

Install

The following only holds true at the time of writing this. Follow directions located on the asdf wiki.

$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.1
$ nano ~/.bashrc
# Append the following:
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash

Add plugins

The following plugins are required to run rails:

  • nodejs
  • ruby
  • sqlite
  • yarn
$ asdf plugin add nodejs && asdf plugin add ruby && asdf plugin add sqlite && asdf plugin add yarn
$ asdf install nodejs latest && asdf install ruby latest && asdf install sqlite latest && asdf install yarn latest
$ asdf list # take note of versions
$ asdf global nodejs VERSION && asdf global ruby VERSION && asdf global sqlite VERSION && asdf global yarn VERSION

Add postgres (optional)

By default, rails will use sqlite. Sqlite is a small, fast, containerized database engine. This is fine for development. For staging or production, postgres or mysql should be used.

$ asdf plugin add postgres
$ asdf install postgres latest
$ asdf list # take note of versions
$ asdf global postgres VERSION
$ pg_ctl start # start PostgreSQL server

Add .irbrc (optional)

~/.irbrc is loaded when irb is executed. The bash method clear is not available while in irb. I replicated it in ruby. The method is cross platform, and works with ruby >= 2.7.0.

# required_ruby_version = ">= 2.7.0"
require 'io/console'

def clear
	original_return_format = conf.return_format
	$stdout.clear_screen
	conf.return_format = ""
end

Rails

Install

asdf

$ gem install rails

Create new app

--database is an optional parameter. Default database is sqlite.

$ rails new APP_PATH [--database=postgresql]
$ cd APP_PATH
$ rails s

Spina CMS

Spina CMS is an easy to use CMS for rails 6+.

Dependancies

Rails and postgres must be installed (and running).

Create spina app

$ rails new APP_PATH --database=postgresql
$ cd APP_PATH
$ nano Gemfile
# Append the following:
gem 'spina'
$ bundle
$ rails g spina:install
$ nano config/initializers/assets.rb
# Append the following:
Rails.application.config.assets.precompile += %w( default/application.css )
$ rake db:create
$ rake db:migrate
$ rails s

Asset frameworks

Milligram

Milligram is a minimalist CSS framework.

$ cd APP_PATH
$ nano Gemfile
# Append the following:
gem 'milligram'
$ nano app/assets/stylesheets/defaulty/application.css.sass
# Append the following:
@import "milligram"
$ bundle
$ nano 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment