Polymorphic Selects in Rails using GlobalIDs Discussion
This is fantastic Chris thank you, I'm curious how this would work for the edit view of the form?
You'll need to set the expires_in: nil
parameter to have idempotent signed ids generated.
Document.find(5).to_sgid(expires_in: nil)
Documented here https://github.com/rails/globalid
This way your browser will be able to display the currently selected value from the list of options.
Chris, I usually don’t want to leak IDs so I use uuid columns for that, and also change to_param to return the uuid. Do you also think this is a suitable replacement for that use case?
I'm having a hard time figuring out how to set the default value when editing the form. Anyone else have that working?
If it helps anyone else, I figured it out. You have to make sure to add expires_in: nil
to your :to_sgid
method; otherwise, when you send in the default value, it will use a new expiry, won't match any of the options, and won't mark and display any option as 'selected.'