diff options
author | José Valim <jose.valim@gmail.com> | 2011-03-31 19:00:05 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-03-31 19:00:05 +0200 |
commit | 7a9dafd96cd4735b9134081f1d8103a6c62a6809 (patch) | |
tree | b7e9ccb480e26c04fd715c1c8d024bac41ae5ce5 | |
parent | b45302d7676a5e38d82662f9068ee6d832ff2e3c (diff) | |
download | rails-7a9dafd96cd4735b9134081f1d8103a6c62a6809.tar.gz rails-7a9dafd96cd4735b9134081f1d8103a6c62a6809.tar.bz2 rails-7a9dafd96cd4735b9134081f1d8103a6c62a6809.zip |
Improve docs.
-rw-r--r-- | actionpack/lib/action_controller/metal/responder.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index 3d009e3de3..59a3621f72 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -77,6 +77,37 @@ module ActionController #:nodoc: # # respond_with(@project, :manager, @task) # + # === Custom options + # + # <code>respond_with</code> also allow you to pass options that are forwarded + # to the underlying render call. Those options are only applied success + # scenarios. For instance, you can do the following in the create method above: + # + # def create + # @project = Project.find(params[:project_id]) + # @task = @project.comments.build(params[:task]) + # flash[:notice] = 'Task was successfully created.' if @task.save + # respond_with(@project, @task, :status => 201) + # end + # + # This will return status 201 if the task was saved with success. If not, + # it will simply ignore the given options and return status 422 and the + # resource errors. To customize the failure scenario, you can pass a + # a block to <code>respond_with</code>: + # + # def create + # @project = Project.find(params[:project_id]) + # @task = @project.comments.build(params[:task]) + # respond_with(@project, @task, :status => 201) do |format| + # if @task.save + # flash[:notice] = 'Task was successfully created.' + # else + # format.html { render "some_special_template" } + # end + # end + # end + # + # Using <code>respond_with</code> with a block follows the same syntax as <code>respond_to</code>. class Responder attr_reader :controller, :request, :format, :resource, :resources, :options |