| CARVIEW |
plataformatec / responders
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (1)
- Wiki (1)
- Graphs
-
Branch:
master
-
Branches (1)
- master ✓
- Tags (1)
Pledgie Donations
Once activated, we'll place the following badge in your repository's detail box:
A set of Rails 3 responders to dry up your application — Read more
| name | age | message | |
|---|---|---|---|
| |
CHANGELOG.rdoc | Tue Dec 22 10:15:43 -0800 2009 | Bump to 0.4 which Inherited Resources will fina... [josevalim] |
| |
MIT-LICENSE | Fri Dec 04 04:55:35 -0800 2009 | Add License. [josevalim] |
| |
README.rdoc | Tue Dec 22 10:15:43 -0800 2009 | Bump to 0.4 which Inherited Resources will fina... [josevalim] |
| |
Rakefile | Wed Dec 02 16:10:24 -0800 2009 | Added FlashResponder. [josevalim] |
| |
lib/ | Tue Jan 05 15:30:16 -0800 2010 | Version bump. [josevalim] |
| |
test/ | Thu Dec 24 01:27:20 -0800 2009 | Do not cache new resources in HttpCacheResponder [josevalim] |
Responders
A set of responders modules to dry up your Rails 3 app:
- 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: 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. 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 as well:
Responders::FlashResponder.flash_keys = [ :success, :failure ]
- 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.
Configuring your own responder
The first step is instal responders gem and configure it in your application:
sudo gem install responders
Responders only provides a set of modules, to use them, you have to create your own responder. This can be done in an initializer for example:
class AppResponder < ActionController::Responder
include Responders::FlashResponder
include Responders::HttpCacheResponder
end
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 just by configuring your environment:
config.generators do |g|
g.scaffold_controller = :responders_controller
end
Bugs and Feedback
If you discover any bugs or want to drop a line, feel free to create an issue on GitHub.
github.com/plataformatec/responders/issues
MIT License. Copyright 2009 Plataforma Tecnologia. blog.plataformatec.com.br
