Installation

If you are including this gem to support backwards compatibilty for responders in previous releases of Rails, you only need to include the gem and bundle.

$ bundle install

Responders Types

FlashResponder

Sets the flash based on the controller action and resource status.
For instance, if you do: respond_with(@post) on a POST request and the resource @post
does not contain errors, it will automatically set the flash message to
"Post was successfully created" as long as you configure your I18n file:

flash:actions:create:notice:"%{resource_name} was successfully created."update:notice:"%{resource_name} was successfully updated."destroy:notice:"%{resource_name} was successfully destroyed."alert:"%{resource_name} could not be destroyed."

In case the resource contains errors, you should use the failure key on I18n. This is
useful to dry up flash messages from your controllers. Note: by default alerts for update
and destroy actions are commented in generated I18n file. If you need a specific message
for a controller, let's say, for PostsController, you can also do:

flash:posts:create:notice:"Your post was created and will be published soon"

This responder is activated in all non get requests. By default it will use the keys
:notice and :alert, but they can be changed in your application:

config.responders.flash_keys = [ :success, :failure ]

You can also have embedded HTML. Just create a _html scope.

flash:actions:create:alert_html:"<strong>OH NOES!</strong> You did it wrong!"posts:create:notice_html:"<strong>Yay!</strong> You did it!"

See also the namespace_lookup option to search the full hierarchy of possible keys.

HttpCacheResponder

Automatically adds Last-Modified headers to API requests. This
allows clients to easily query the server if a resource changed and if the client tries
to retrieve a resource that has not been modified, it returns not_modified status.

CollectionResponder

Makes your create and update action redirect to the collection on success.

LocationResponder

This responder allows you to use callable objects as the redirect location.
Useful when you want to use the respond_with method with
a custom route that requires persisted objects, but the validation may fail.

Note: this responder is included by default, and doesn't need to be included
on the top of your controller (including it will issue a deprecation warning).

Now you would see the message "bob@bob.com was successfully created" instead of the default "Invitation was successfully created."

Generator

This gem also includes a responders controller generator, so your scaffold can be customized
to use respond_with instead of default respond_to blocks. From 2.1, you need to explicitly opt-in to use this generator by adding the following to your config/application.rb: