Skip to content

Instantly share code, notes, and snippets.

@BrianSigafoos
Last active August 26, 2017 14:54
Show Gist options
  • Save BrianSigafoos/b609b9c36c1b1fefa5431c525266e45b to your computer and use it in GitHub Desktop.
Save BrianSigafoos/b609b9c36c1b1fefa5431c525266e45b to your computer and use it in GitHub Desktop.
Rails setup notes

Rails + React + PostgreSQL on Heroku

$ rails new <app-name> --database=postgresql --webpack=react
$ cd <app-name>
$ echo '.idea' >> .gitignore      # remove RubyMine's config
$ echo "ruby '2.4.0'" >> Gemfile  # for Heroku Ruby version
$ git add .
$ git commit -m "Initial commit"

# Create new repo on GitHub with same name...
$ git remote add origin git@github.com:BrianSigafoos/<app-name>.git
$ git push -u origin master

# Heroku setup
$ heroku create
$ git push heroku master

# Heroku helpers
$ heroku run rails console
$ heroku run rake db:migrate  # or any rake task

# Use secrets.yml.enc - encoded secrets file committed to git
$ bin/rails secrets:setup
# save the encryption key (in git ignored secrets.yml) in a pw manager
$ heroku config:set RAILS_MASTER_KEY=[encryption key]
# check keys
$ heroku config

# push local branch to Heroku master
$ git push heroku localbranch:master

Rails API + PostgreSQL

$ rails new <app-name> --api --database=postgresql
$ cd <app-name>
$ echo '.idea' >> .gitignore
$ echo 'ruby-2.4.0' >> .ruby-version 
$ echo "gem 'rubocop', require: false" >> Gemfile
$ echo "gem 'annotate'" >> Gemfile
$ bundle install
# Annotate gem usage: 
$ annotate --exclude tests,fixtures,factories,serializers   # manually, just models
$ rails g annotate:install   # turn on automatic annotations, modify new rake task below
$ skip_on_db_migrate=1 rails db:migrate  # to skip auto annotate for a migration

Annotate gem rake task

lib/tasks/auto_annotate_models.rake

# frozen_string_literal: true
# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
if Rails.env.development?
  task :set_annotation_options do
    # You can override any of these by setting an environment variable of the
    # same name.
    Annotate.set_defaults(
      'position_in_routes'   => 'before',
      'position_in_class'    => 'before',
      'position_in_test'     => 'before',
      'position_in_fixture'  => 'before',
      'position_in_factory'  => 'before',
      'show_indexes'         => 'true',
      'simple_indexes'       => 'false',
      'model_dir'            => 'app/models',
      'include_version'      => 'false',
      'require'              => '',
      'exclude_tests'        => 'true',  # changed
      'exclude_fixtures'     => 'true',  # changed
      'exclude_factories'    => 'true',  # changed
      'ignore_model_sub_dir' => 'false',
      'skip_on_db_migrate'   => 'false',
      'format_bare'          => 'true',
      'format_rdoc'          => 'false',
      'format_markdown'      => 'false',
      'sort'                 => 'true',  # changed
      'force'                => 'false',
      'trace'                => 'false'
    )
  end

  Annotate.load_tasks
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment