lib/rabl/partials.rb in rabl-0.7.5 vs lib/rabl/partials.rb in rabl-0.7.6
- old
+ new
@@ -19,9 +19,10 @@
# object_to_hash(@user, :source => "...") { attribute :full_name } => { ... }
# object_to_hash([@user], :source => "...") { attribute :full_name } => { ... }
# options must have :source (rabl file contents)
# options can have :source_location (source filename)
def object_to_hash(object, options={}, &block)
+ return object if object.nil?
return [] if is_collection?(object) && object.blank? # empty collection
engine_options = options.reverse_merge(:format => "hash", :view_path => @_view_path, :root => (options[:root] || false))
Rabl::Engine.new(options[:source], engine_options).render(@_scope, :object => object, &block)
end