From 0b25eefb38daaff13b9ec9a55b7ccfffc5b5b74e Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Mon, 17 Dec 2018 07:43:51 -0500 Subject: [PATCH] Allow identifier lookup for scope based find_record implementation --- lib/dunlop/ember/api_base_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/dunlop/ember/api_base_controller.rb b/lib/dunlop/ember/api_base_controller.rb index 86c0483..2d3f763 100644 --- a/lib/dunlop/ember/api_base_controller.rb +++ b/lib/dunlop/ember/api_base_controller.rb @@ -144,7 +144,11 @@ module Dunlop::Ember::ApiBaseController def find_record(options = {}) scope = record_scope scope = scope.includes(*Array.wrap(options[:includes])) if options[:includes] - @record = scope.find(params[:id]) + if record_class.include?(HasUuidIdentifier) and HasUuidIdentifier::UUID_MATCH =~ params[:id].to_s + @record = scope.find_by(identifier: params[:id]) or raise ActiveRecord::RecordNotFound # I (Benjamin) don't agree with this (raising) behaviour, but this is the rails standard for raising and rescue + else + @record = scope.find(params[:id]) + end end def record_params