I'm making changes to a Rails site which uses ActiveAdmin, including changing the identifiers used in URLs to meaningful strings.
Outside of ActiveAdmin, it was enough to change the to_param
method of each model. That also changed the URLs generated for links on ActiveAdmin pages, but to get the ActiveAdmin models to respond to the new URLs also required changing the ActiveAdmin registrations as described in this answer.
One of the models on this site uses dots/periods in some of the meaningful identifiers. (This is not something I can change.) Rails' recognition of formats based on extensions causes problems for these records. Outside of ActiveAdmin, those problems can be resolved by changing the id constraints on the routes as described in this answer. (Allowing format-specifying extensions on top of this requires some extra work in the controller.) Unfortunately, changing the constraints on non-ActiveAdmin routes has no effect on any ActiveAdmin routes. It is possible to manually specify ActiveAdmin routes (rather than relying solely on ActiveAdmin.routes(self)
), as described in this answer, but I have not found a way to do so that allows the same change in constraints that works for the non-ActiveAdmin routes.
How can I change the constraints on ids in ActiveAdmin routes to allow inclusion of dots?
Here are two attempts that get the routing right but fail to allow dots:
get "/admin/motors/:id", id: /[^\/]+/, controller: "admin/motors", action: "show"
get "/admin/motors/:id", constraints: { :id => /[^\/]+/ }, controller: "admin/motors", action: "show"