public
Description: response for lets you decorate your actions respond_to blocks
Homepage: http://blog.ardes.com/response_for
Clone URL: git://github.com/ianwhite/response_for.git
Click here to lend your support to: response_for and make a donation at www.pledgie.com !
Updated README with more notes about 0.2 change
ianwhite (author)
Wed Sep 17 14:16:04 -0700 2008
commit  6a8d4ccf3f97b7ec21c6cd86f52da3f68e87b3c3
tree    fd40f143bf0e828e669742acd8fd4f4a8656e577
parent  7700d0813bc19faf0e2d8834f3c83c29379b4988
...
6
7
8
9
 
10
11
12
...
16
17
18
19
20
21
22
...
59
60
61
62
63
 
 
64
65
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
68
 
 
 
 
 
 
 
 
 
 
 
69
70
71
...
6
7
8
 
9
10
11
12
...
16
17
18
 
19
20
21
...
58
59
60
 
 
61
62
63
 
 
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
0
@@ -6,7 +6,7 @@ response_for (see Ardes::ResponseFor::ClassMethods) allows you to decorate the r
0
 
0
 As of version 0.2.0, response_for's functionality can be summed up in one sentence:
0
 
0
-"response_for allows you to specify default responses for any action (or before filter) that doesn't render or redirect"
0
+<b>"response_for allows you to specify default responses for any action (or before filter) that doesn't render or redirect"</b>
0
 
0
 Actions typically do two things - interact with models, and render a response.  The above simple idea allows you to decouple these
0
 two functions (where appropriate), which means abstraction of common patterns becomes possible.
0
@@ -16,7 +16,6 @@ You should use 0.1-stable in your existing projects until you have runs your spe
0
 
0
 If you want to know more about why I changed the API in 0.2 look at the bottom of this README
0
 
0
-
0
 === Example
0
 
0
   class FooController < ApplicationController
0
@@ -59,13 +58,40 @@ headaches, such as:
0
   respond_to_without_response_for in any bail out code.
0
 * Conceptually, overriding code declared in methods, with code declared at the class level, is weird.  Here's an example
0
 
0
-  class FooController < SuperclassController
0
-    response_for :index # override Superclass's index respond_to
0
+    class FooController < SuperclassController
0
+      response_for :index # override Superclass's index respond_to
0
     
0
-    def index
0
-      respond_to  # one might expect this to override the above, as its declared later - but it wont!
0
+      def index
0
+        respond_to  # one might expect this to override the above, as its declared later - but it wont!
0
+      end
0
+    end
0
+
0
+So, in 0.2 a much simpler idea is behind response_for - you can declare a default response for an action which will be performed
0
+if <b>that that action has not already performed a render or redirect</b>.  This means that all of your bail out code written with
0
+respond_to will do what it's supposed to.
0
+
0
+==== Rewriting for 0.2
0
+
0
+If you're upgrading, you just need to convert any actions you want to override from this:
0
+
0
+  def index
0
+    @things = Thing.all
0
+    respond_to do |format|
0
+      format.html
0
+      format.xml { render :xml => @things }
0
     end
0
   end
0
+  
0
+to this:
0
+
0
+  def index
0
+    @things = Thing.all
0
+  end
0
+  
0
+  response_for :index fo |format|
0
+    format.html
0
+    format.xml { render :xml => @things }
0
+  end
0
 
0
 == Previous Versions: 0.1
0
 
...
151
152
153
154
 
155
156
157
158
159
 
160
161
162
163
164
 
165
166
167
168
 
169
170
...
151
152
153
 
154
155
156
157
158
 
159
160
161
162
163
 
164
165
166
167
 
168
169
170
0
@@ -151,20 +151,20 @@ StackingResponsesSpec::TheController with responses conditionally executed GET :
0
 - should render :action => :foo (the default response)
0
 
0
 StackingResponsesSpec::TheController with responses conditionally executed GET :foo, :second => true
0
-- should execute second, then first, then in html second, response
0
+- should execute second, then first, then html second, response
0
 - should redirect from second response
0
 - should NOT execute first html response
0
 
0
 StackingResponsesSpec::TheController with responses conditionally executed GET :foo, :first => true
0
-- should execute second, then first, then in first html response
0
+- should execute second, then first, then first html response
0
 - should redirect from first response
0
 - should NOT execute second html response
0
 
0
 StackingResponsesSpec::TheController with responses conditionally executed GET :foo, :first => true, :second => true (can't execute two html blocks)
0
-- should execute second, then first, then in second html response
0
+- should execute second, then first, then second html response
0
 - should redirect from second response
0
 - should NOT execute first html response
0
 
0
-Finished in 0.729328 seconds
0
+Finished in 0.494693 seconds
0
 
0
 92 examples, 0 failures

Comments