Skip to content

Instantly share code, notes, and snippets.

@romchambe
Last active September 18, 2018 13:53
Show Gist options
  • Select an option

  • Save romchambe/f5812797f7cac1513edcda5e1371acb0 to your computer and use it in GitHub Desktop.

Select an option

Save romchambe/f5812797f7cac1513edcda5e1371acb0 to your computer and use it in GitHub Desktop.
Setup of SSL certificate on Heroku with Gandi

SSL setup: https://vimeo.com/209534466

Creating a join table

rails g migration CreateJoinTableGameInvitesInvitees game_invites invitees

  • Models linked together must be in alphabetical order when naming the migration file
  • the columns can be given any names as long as they are correctly associated in the model file:
has_and_belongs_to_many :invitees, class_name: 'User', foreign_key: 'invitee_id', #the associated column and the alien model
                        join_table: 'game_invites_invitees', #name of the join table
                        association_foreign_key: 'game_invite_id' #the name of the domestic model in the join table

Using enums

Use UUIDs as database IDs (with pg)

Original article

Supposing we are using Postgre as a database, it only takes the following steps to use UUIDs as database IDs instead of incremental ones:

  1. Generate a migration: rails g migration EnablePgcryptoExtension
  2. Modify the migration file to this:
class EnablePgcryptoExtension < ActiveRecord::Migration[5.1]
  def change
    enable_extension 'pgcrypto'
  end
end
  1. Tell ActiveRecord that the new generator for IDs should be UUIDs:
#config/application.rb 
config.generators do |g|
  g.orm :active_record, primary_key_type: :uuid
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment