mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Handle render.ams with nil serializer or adapter
This commit is contained in:
parent
84197e4dad
commit
ec5dc497b0
@ -20,6 +20,7 @@ module ActiveModel
|
|||||||
class Serializer
|
class Serializer
|
||||||
extend ActiveSupport::Autoload
|
extend ActiveSupport::Autoload
|
||||||
autoload :Adapter
|
autoload :Adapter
|
||||||
|
autoload :Null
|
||||||
include Configuration
|
include Configuration
|
||||||
include Associations
|
include Associations
|
||||||
include Attributes
|
include Attributes
|
||||||
|
|||||||
17
lib/active_model/serializer/null.rb
Normal file
17
lib/active_model/serializer/null.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
module ActiveModel
|
||||||
|
class Serializer
|
||||||
|
class Null < Serializer
|
||||||
|
def attributes(*)
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
def associations(*)
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
def serializable_hash(*)
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -81,7 +81,10 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def notify_render_payload
|
def notify_render_payload
|
||||||
{ serializer: serializer, adapter: adapter }
|
{
|
||||||
|
serializer: serializer || ActiveModel::Serializer::Null,
|
||||||
|
adapter: adapter || ActiveModelSerializers::Adapter::Null
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user