Skip to content

Instantly share code, notes, and snippets.

@nicholasshirley
nicholasshirley / ActiveStorage purge on controller
Last active April 17, 2018 11:29
Example of selective attachment purge on controller
@resource = Training::Resource.find(params[:id])
if params[:attachment_id]
@resource.files.find_by_id(params[:attachment_id]).purge
flash[:success] = 'The resource has been deleted'
redirect_to edit_trainings_resource_path(@resource)
else
@resource.destroy
flash[:success] = 'The resource has been deleted'
redirect_to trainings_resources_path
@nicholasshirley
nicholasshirley / DO_cap_no_AR.md
Last active December 30, 2018 02:28
Set up DO Rails + nginx + Puma + Capistrano (No ActiveRecord)

Steps to get droplet up and running with just Ubuntu 16.04

  1. Create non-root user
adduser production
usermod -aG sudo production
ssh-keygen
cat ~/.ssh/id_rsa.pub

Goal

A build template for static sites that is:

  1. Extensible as requirements upgrade
  2. Buildable to optimize deployments
  3. Repeatable (reuse as many common elements as possible/only customize when necessary)
  4. SEO friendly

Tools to meet goals

  1. Encapsulate everything in Vue components
  2. Use webpack & co (e.g. purgeecss)

This setup is for this template. It runs Rails in API mode, Vue + Webpack for view layer and it's all served from the same root directory.

Steps to get droplet up and running with just Ubuntu 16.04 (i.e. not a "one-click" install)

  1. Create non-root user
adduser production
usermod -aG sudo production