Skip to content

Instantly share code, notes, and snippets.

@benhawker
benhawker / friendly_urls.markdown
Created July 19, 2017 20:45 — forked from cdmwebs/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@benhawker
benhawker / script.rb
Created December 5, 2017 16:01
Hacky script to take a look at some Honeybadger errors
require 'rubygems'
require 'colorize'
token = 'INSERT_YOUR_TOKEN_HERE'
total_notices_count, total_logged_in_count = 0, 0
project_id = 42287
require 'base64'
require 'httparty'
@benhawker
benhawker / Oyster
Created February 13, 2018 11:43
Oyster
```
In order to use public transport
As a customer
I want money on my card
In order to keep using public transport
As a customer
I want to add money to my card
In order to protect my money
@benhawker
benhawker / gist:017add3ae3daa94df433291cbfd28d33
Created February 28, 2018 15:27
Oyster another approach
require './lib/journey'
require './lib/journey_history'
class Oyster
MAX_BALANCE = 50
MIN_FARE = 1.7
attr_reader :balance, :customer_id, :journey_history
def initialize(balance: 0, customer_id:)