Here's how I set up a tiny Nginx/Rails server that uses HTTPS via a Let's Encrypt issued certificate.
I use the smallest DigitalOcean droplet (512 MB) here, which is built from the "Ubuntu Ruby on Rails on 14.04" image provided by them.
# db/migrate/20110714024435_split_author.rb | |
class SplitAuthor < ActiveRecord::Migration | |
def self.up | |
Post.where(:author=>nil).each do |p| | |
author = Author.create!(:name => p.author_name, | |
:account_id => p.account_id) | |
p.author = author | |
p.save! | |
end | |
end |
Here's how I set up a tiny Nginx/Rails server that uses HTTPS via a Let's Encrypt issued certificate.
I use the smallest DigitalOcean droplet (512 MB) here, which is built from the "Ubuntu Ruby on Rails on 14.04" image provided by them.
user nginx; | |
worker_processes 5; | |
error_log /var/log/nginx.error.log; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
class InvitationsController < Devise::InvitationsController | |
# GET /resource/invitation/accept?invitation_token=abcdef | |
def edit | |
if params[:invitation_token] && self.resource = resource_class.to_adapter.find_first( :invitation_token => params[:invitation_token] ) | |
session[:invitation_token] = params[:invitation_token] | |
render :edit | |
else | |
set_flash_message(:alert, :invitation_token_invalid) | |
redirect_to after_sign_out_path_for(resource_name) |
newpg=9.6.1 # set to new PG version number | |
oldpg=`pg_config --version | cut -d' ' -f2` | |
# PG 96. upgrades the readline to v7, which breaks anything linked against readline v6, like ruby via ruby-build. | |
# I *think* this should prevent it from installing v7. But if weird shit happens with various rubies, | |
# you'll have to reinstall them. | |
brew pin readline | |
# Stop current Postgres server | |
brew services stop postgresql |
require 'rubygems' | |
require 'middleman/rack' | |
protected_middleman = Rack::Auth::Basic.new(Middleman.server) do |username, password| | |
[username, password] == ['theuser', 'thepassword'] | |
end | |
run protected_middleman |
connection = Faraday::Connection.new('http://example.com') do |builder| | |
builder.request :url_encoded # for POST/PUT params | |
builder.adapter :net_http | |
end | |
# same as above, short form: | |
connection = Faraday.new 'http://example.com' | |
# GET | |
connection.get '/posts' |
SSH into Root
$ ssh root@123.123.123.123
Change Root Password
#!/bin/bash | |
# Stop all containers | |
containers=`docker ps -a -q` | |
if [ -n "$containers" ] ; then | |
docker stop $containers | |
fi | |
# Delete all containers | |
containers=`docker ps -a -q` | |
if [ -n "$containers" ]; then | |
docker rm -f -v $containers |
It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media
This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.