public
Description: resources_controller rails plugin: rc makes RESTful controllers fun
Homepage: http://plugins.ardes.com/doc/resources_controller
Clone URL: git://github.com/ianwhite/resources_controller.git
Click here to lend your support to: resources_controller and make a donation at www.pledgie.com !
Removed deprecation warnings from save_resource, and added warnings in the
comments.
ianwhite (author)
Fri Oct 10 17:59:26 -0700 2008
commit  454b4dc8c69bf417edb4a6d2f9ef8847b94ee42c
tree    f76625cf530bfea51fa9b67731351715ef678e40
parent  40174b572fa933173d5d3c1983eaad7da015b13f
...
652
653
654
655
656
657
 
 
 
 
 
 
 
 
 
 
658
659
660
 
 
 
661
662
663
 
 
 
 
 
 
664
665
 
666
667
668
669
670
...
652
653
654
 
 
 
655
656
657
658
659
660
661
662
663
664
665
 
 
666
667
668
669
670
 
671
672
673
674
675
676
677
 
678
679
 
680
681
682
0
@@ -652,19 +652,31 @@ module Ardes#:nodoc:
0
         @enclosing_collection_resources ||= []
0
       end
0
       
0
-      # Has the resource been saved successfully?
0
-      # If the record has not had validation attempted, it is saved.
0
-      # Returns true if the record is not new, and there are no errors
0
+      # NOTE: This method is overly complicated and unecessary.  It's much clearer just to keep
0
+      # track of record saves yourself, this is here for BC.  For an example of how it should be
0
+      # done look at the actions module in http://github.com/ianwhite/response_for_rc
0
+      #
0
+      # Has the resource been saved successfully?, if no save has been attempted, save the
0
+      # record and return the result
0
+      #
0
+      # This method uses the @resource_saved tracking var, or the model's state itself if
0
+      # that is not available (which means if you do resource.update_attributes, then this
0
+      # method will return the correct result)
0
       def resource_saved?
0
-        resource.save unless resource.validation_attempted?
0
-        resource.saved?
0
+        save_resource if @resource_saved.nil? && !resource.validation_attempted?
0
+        @resource_saved = resource.saved? if @resource_saved.nil?
0
+        @resource_saved
0
       end
0
       
0
-      # DEPRECATED: just use resource.save
0
+      # NOTE: it's clearer to just keep track of record saves yourself, this is here for BC
0
+      # See the comment on #resource_saved?
0
+      #
0
+      # @resource_saved = resource.update_attributes(params[resource_name])
0
+      #
0
+      # Save the resource, and keep track of the result
0
       def save_resource
0
-        resource.save
0
+        @resource_saved = resource.save
0
       end
0
-      deprecate :save_resource => 'Use resource.save'
0
       
0
     private
0
       # returns the route that was used to invoke this controller and current action.  The path is found first from params[:resource_path]

Comments