lib/dejavu.rb in dejavu-0.2.0 vs lib/dejavu.rb in dejavu-0.2.1
- old
+ new
@@ -38,13 +38,22 @@
end
module ControllerMethods
def save_for_dejavu(obj, opts = {})
attrs = obj.attributes
+
+ missing_keys = obj.errors.keys.map(&:to_sym).select{|x| obj.respond_to?(x)} - attrs.keys.map(&:to_sym)
+
if keys = opts[:nested]
keys = [keys] unless keys.is_a? Array
keys.each { |key| attrs = save_nested_for_dejavu(obj, key, attrs) }
+ missing_keys -= keys.map(&:to_sym)
end
+
+ missing_keys.each do |key|
+ attrs[key] = obj.send(key)
+ end
+
flash[:"saved_#{obj.class.model_name.underscore}_for_redisplay"] = attrs
end
private