Mark Grealish

the life and code of a crazy cat man


Pretty Stack Overflow-style resource URLs in Rails 5

in code

Stack Overflow uses routes with the format /:id/:title for questions like this one, which I find to be more memorable than simply a terse ID. I’ve decided that I want this for my new project, a rewrite of this blog in Ruby on Rails 5. Small changes to a model and its routes are required to permit this:

Routes

A post on Stack Overflow led me to a GitHub issue which outlined breaking changes in the to_param object method and a need to glob the route.

get '/ponies/*id', to: 'ponies#show', as: :pony

Model

Add your custom slug:

class Pony < ApplicationRecord
  def to_param
    "#{id}/#{name.parameterize}"
  end
end

And that’s it, simple as.


The Summer Day

in random

The Summer Day
Who made the world?
Who made the swan, and the black bear?
Who made the grasshopper?
This grasshopper, I mean-
the one who has flung herself out of the grass,
the one who is eating sugar out of my hand,
who is moving her jaws back and forth instead of up and down-
who is gazing around with her enormous and complicated eyes.
Now she lifts her pale forearms and thoroughly washes her face.
Now she snaps her wings open, and floats away.
I don’t know exactly what a prayer is.
I do know how to pay attention, how to fall down
into the grass, how to kneel down in the grass,
how to be idle and blessed, how to stroll through the fields,
which is what I have been doing all day.
Tell me, what else should I have done?
Doesn’t everything die at last, and too soon?
Tell me, what is it you plan to do
with your one wild and precious life?
-Mary Oliver

The Summer Day


I triggered a tickle fight at 3am

in family

I find nothing to complain about in such a crazy turn of events.

Caira
Garrett

So she took my glasses and called herself a dumb nerd

in family

This is the cross I bear. My niece is the worst. Woe is me. Life is pain.

FIXME
Ella wearing my glasses

A (glitchy) Irish country home

in ireland

Taken from a bus somewhere in Westmeath.

A glitchy Irish home

Slieve Gullion and the Mountains of Mourne from Leopardstown

in ireland

Taken while I leant out my bedroom window, of all places!

Slieve Gullion and the Mountains of Mourne