Skip to content

Commit

Permalink
Fix Rails 6.0 'url delegated to attachment but attachment is nil'.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregschmit committed Apr 3, 2023
1 parent ac5e704 commit 2d8240e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rest_framework/serializers.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 2d8240e

Please sign in to comment.