URL-safe Base64 for use in routes and params
jeremy opened this issue · comments
Jeremy Daer commented
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
Ben Crouse commented
I added a pull request here #11
Jeremy Daer commented
Implemented by @bencrouse 😁