-
We're using integer IDs as primary keys and UUIDs for public IDs in multiple models. I'd like to be able to link a to certain record in Avo using the UUID from a 3rd party service:
Which of course doesn't work now as it expects the integer ID:
Is this something that may be added as a feature? Or is there any workaround how to achieve this? All I could come up with is to use search, which I've configured to work with both IDs exact match, but that is not possible to link to – if I could do something like:
That would probably be fine, as it is just one more click. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
OK, I might have found a workaround. I just added a new route: Rails.application.routes.draw do
authenticate :user, ->(user) { user.super_admin? } do
mount Avo::Engine, at: Avo.configuration.root_path
scope Avo.configuration.root_path, module: "avo" do
get "l/:resources/:id", to: "redirect#redirect", as: "dashboard_permalink"
end
end and a controller: # app/controllers/avo/redirect_controller.rb
class Avo::RedirectController < ApplicationController
def redirect
avo_resource_name = params[:resources].singularize
avo_resource_class_name = "Avo::Resources::#{avo_resource_name.classify}"
avo_resource_class = avo_resource_class_name.safe_constantize
return redirect_to Avo::Engine.routes.url_helpers.root_path, alert: "Resource `#{avo_resource_class_name}` doesn't exist." unless avo_resource_class.present?
id = params[:id]
model_class = avo_resource_class.model_class
if model_class.has_attribute?(:public_id)
record = model_class.find_by!(public_id: id)
else
record = model_class.find(id)
end
avo_path = Avo::Engine.routes.url_helpers.public_send(:"resources_#{avo_resource_name}_path", record.id)
redirect_to avo_path
end
end And now I can do e.g. Well, sorted out for me as of now, but maybe still worth a shot being able to handle public IDs somehow directly in Avo. |
Beta Was this translation helpful? Give feedback.
OK, I might have found a workaround.
I just added a new route:
and a controller: