lib/dejavu.rb in dejavu-0.1.0 vs lib/dejavu.rb in dejavu-0.1.1
- old
+ new
@@ -11,11 +11,15 @@
is_instance = ActiveRecord::Base === obj
model_name = is_instance ? obj.class.model_name.underscore : obj.to_s
if has_dejavu?(obj)
foo = if is_instance
- obj.attributes = flash[:"saved_#{model_name}_for_redisplay"]
+ if Rails::VERSION::MINOR >= 1
+ obj.assign_attributes(flash[:"saved_#{model_name}_for_redisplay"], :without_protection => true)
+ else
+ obj.attributes = flash[:"saved_#{model_name}_for_redisplay"]
+ end
obj
else
obj.to_s.classify.constantize.new flash[:"saved_#{model_name}_for_redisplay"]
end
foo.valid?
@@ -25,11 +29,15 @@
end
end
end
module ControllerMethods
- def save_for_dejavu(obj)
- flash[:"saved_#{obj.class.model_name.underscore}_for_redisplay"] = obj.attributes
+ def save_for_dejavu(obj, opts = {})
+ attrs = obj.attributes
+ if opts[:nested]
+ attrs["#{opts[:nested]}_attributes"] = obj.send(opts[:nested]).attributes
+ end
+ flash[:"saved_#{obj.class.model_name.underscore}_for_redisplay"] = attrs
end
end
end
ActionController::Base.send(:include, Dejavu::ControllerMethods)