From 2d8240e2024d58c4f07bc0bd49f30e62fdb941e5 Mon Sep 17 00:00:00 2001 From: "Gregory N. Schmit" Date: Mon, 3 Apr 2023 01:02:11 -0500 Subject: [PATCH] Fix Rails 6.0 'url delegated to attachment but attachment is nil'. --- lib/rest_framework/serializers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rest_framework/serializers.rb b/lib/rest_framework/serializers.rb index ce2d590..d0b11bd 100644 --- a/lib/rest_framework/serializers.rb +++ b/lib/rest_framework/serializers.rb @@ -277,11 +277,11 @@ def _get_controller_serializer_config(fields) serializer_methods[f] = f if ref.macro == :has_one_attached self.define_singleton_method(f) do |record| - next record.send(f).url + next record.send(f).attachment&.url end else self.define_singleton_method(f) do |record| - next record.send(f).map(&:url) + next record.send(f).map { |x| x.attachment&.url } end end elsif @model.method_defined?(f)