rails / globalid

Identify app models with a URI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

URL-safe Base64 for use in routes and params

jeremy opened this issue · comments

Global IDs can be URI-escaped and embedded in an app's routes and query params, but the percent escaping and needless detail makes a mess of the URL.

Let's provide a nice compact #to_param representation for these cases:

Person.find(1).gid.to_param
# => "Z2lkOi8vYXBwL1BlcnNvbi8x"

(That's just def to_param; Base64.strict_encode64 to_s end)

The locator can try to Base64-decode non-URI arguments:

GlobalID::Locator.locate "Z2lkOi8vYXBwL1BlcnNvbi8x"
# => Person id=1

I added a pull request here #11

Implemented by @bencrouse 😁