(no title)
brandonbloom | 3 years ago
I've encountered a few Rails projects in the wild that do this. One solution is to make liberal use of the `to_param` method. This method converts objects to strings that are intended for use in URLs. Of particular note, it's the identity function for strings and numbers, but returns `.id.to_s` for ActiveRecord models. Using this within definitions makes your function polymorphic for whether it accepts a model or an id.
If you do this widely, would probably be best to monkey-patch in your own `to_id` method.
clintonb|3 years ago