This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
response_for / README.rdoc
| f0b98bf1 » | ian | 2007-10-18 | 1 | = response_for | |
| 2 | |||||
| 570f798d » | ian | 2007-10-23 | 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 | 5 | == Current Version 0.2-stable | |
| 9eb9e429 » | ianwhite | 2008-04-30 | 6 | ||
| 9dc94651 » | ianwhite | 2008-09-13 | 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 | 10 | ||
| 7700d081 » | ianwhite | 2008-09-17 | 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 | 12 | two functions (where appropriate), which means abstraction of common patterns becomes possible. | |
| 9eb9e429 » | ianwhite | 2008-04-30 | 13 | ||
| 7700d081 » | ianwhite | 2008-09-17 | 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 | 20 | === Example | |
| 21 | |||||
| 22 | class FooController < ApplicationController | ||||
| 23 | def index | ||||
| 24 | @foos = Foo.find(:all) | ||||
| 7ce71c62 » | ianwhite | 2008-09-13 | 25 | # default response - render html | |
| 570f798d » | ian | 2007-10-23 | 26 | end | |
| 27 | end | ||||
| 28 | |||||
| 7ce71c62 » | ianwhite | 2008-09-13 | 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 | 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 | 36 | ||
| f0b98bf1 » | ian | 2007-10-18 | 37 | === Specs and Coverage | |
| 38 | |||||
| 41b2cc18 » | ianwhite | 2008-04-30 | 39 | * The SPECDOC lists the specifications | |
| 0aeceda2 » | ianwhite | 2008-06-05 | 40 | * Coverage is 100% (C0), and the spec suite is quite comprehensive | |
| 41b2cc18 » | ianwhite | 2008-04-30 | 41 | ||
| f0b98bf1 » | ian | 2007-10-18 | 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 | 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 | 49 | ||
| 7700d081 » | ianwhite | 2008-09-17 | 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 | 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 | |||||








