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 !
response_for / README.rdoc
f0b98bf1 » ian 2007-10-18 Initial import of response_for 1 = response_for
2
570f798d » ian 2007-10-23 response_for: initial release 3 response_for (see Ardes::ResponseFor::ClassMethods) allows you to decorate the respond_to block of actions on sublcassed controllers. This works nicely with http://plugins.ardes.com/doc/resources_controller
4
9dc94651 » ianwhite 2008-09-13 Final notes and docfixes fo... 5 == Current Version 0.2-stable
9eb9e429 » ianwhite 2008-04-30 Added note about 2.0-stable... 6
9dc94651 » ianwhite 2008-09-13 Final notes and docfixes fo... 7 As of version 0.2.0, response_for's functionality can be summed up in one sentence:
8
9 "response_for allows you to specify default responses for any action (or before filter) that doesn't render or redirect"
37e2d2ed » ianwhite 2008-09-13 Added notes about 0.1 vs 0.... 10
7700d081 » ianwhite 2008-09-17 Updated README with more no... 11 Actions typically do two things - interact with models, and render a response. The above simple idea allows you to decouple these
7ce71c62 » ianwhite 2008-09-13 Updated README 12 two functions (where appropriate), which means abstraction of common patterns becomes possible.
9eb9e429 » ianwhite 2008-04-30 Added note about 2.0-stable... 13
7700d081 » ianwhite 2008-09-17 Updated README with more no... 14 NOTE: 0.2-stable has BC-breaking API changes, and is supported only for Rails >= 2.1.x. Version 0.2.0 was released on Sept 14th 2008.
15 You should use 0.1-stable in your existing projects until you have runs your specs and whatnot.
16
17 If you want to know more about why I changed the API in 0.2 look at the bottom of this README
18
19
570f798d » ian 2007-10-23 response_for: initial release 20 === Example
21
22 class FooController < ApplicationController
23 def index
24 @foos = Foo.find(:all)
7ce71c62 » ianwhite 2008-09-13 Updated README 25 # default response - render html
570f798d » ian 2007-10-23 response_for: initial release 26 end
27 end
28
7ce71c62 » ianwhite 2008-09-13 Updated README 29 # this controller needs to respond_to fbml on index.
30 # Using response_for, we don't need to repeat '@foos = Foo.find(1)'
570f798d » ian 2007-10-23 response_for: initial release 31 class SpecialFooController < FooController
32 response_for :index do |format|
33 format.fbml { render :inline => turn_into_facebook(@foos) }
34 end
35 end
41b2cc18 » ianwhite 2008-04-30 Updated README, and various... 36
f0b98bf1 » ian 2007-10-18 Initial import of response_for 37 === Specs and Coverage
38
41b2cc18 » ianwhite 2008-04-30 Updated README, and various... 39 * The SPECDOC lists the specifications
0aeceda2 » ianwhite 2008-06-05 Fixed typo in README 40 * Coverage is 100% (C0), and the spec suite is quite comprehensive
41b2cc18 » ianwhite 2008-04-30 Updated README, and various... 41
f0b98bf1 » ian 2007-10-18 Initial import of response_for 42 RSpec is used for testing, so the tests are in <tt>spec/</tt> rather than
43 <tt>test/</tt> Do rake --tasks for more details.
44
41b2cc18 » ianwhite 2008-04-30 Updated README, and various... 45 === Continuous Integration
46
47 garlic (at http://github.com/ianwhite/garlic) is used for CI. To run the CI suite have a look at
48 garlic_example.rb
7ce71c62 » ianwhite 2008-09-13 Updated README 49
7700d081 » ianwhite 2008-09-17 Updated README with more no... 50 === Why change the API in 0.2?
51
52 repsonse_for <= v0.1 intercepted respond_to calls to allow overriding of these by class level declarations. This turns out to have some
53 headaches, such as:
54
55 * If you have some bail-out code in before_filters which uses respond_to, then response_for tries to overwrite this. This meant that I had
56 to write response_for to only kick in once before_filters had run. This made for some funky smelling code.
57 * Sometimes your bail out code runs after the before_filters, in a superclass action for example, or just as part of your action (perhaps in
58 another method). The above hack doesn't work for this case (the before_filters have run). The solution in this case was to use
59 respond_to_without_response_for in any bail out code.
60 * Conceptually, overriding code declared in methods, with code declared at the class level, is weird. Here's an example
61
62 class FooController < SuperclassController
63 response_for :index # override Superclass's index respond_to
64
65 def index
66 respond_to # one might expect this to override the above, as its declared later - but it wont!
67 end
68 end
69
7ce71c62 » ianwhite 2008-09-13 Updated README 70 == Previous Versions: 0.1
71
72 There is a branch for rails 2.0 users on this release. If you are using rails 2.0, then you want the 0.1-stable-rails2.0 branch. If you are
73 using rails >= 2.1 then use the 0.1-stable branch
74