aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/mime_responds.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-08-01 16:47:44 +0200
committerJosé Valim <jose.valim@gmail.com>2009-08-07 17:16:16 +0200
commit7034272354ad41dd4d1c90138a79e7f14ebc2bed (patch)
tree51c091d7ff973bbeb1aa2bd7417d0da3a9ed71ba /actionpack/lib/action_controller/metal/mime_responds.rb
parentf59984cc81bd1a64a53a2480a9b4e05fe7357d7c (diff)
downloadrails-7034272354ad41dd4d1c90138a79e7f14ebc2bed.tar.gz
rails-7034272354ad41dd4d1c90138a79e7f14ebc2bed.tar.bz2
rails-7034272354ad41dd4d1c90138a79e7f14ebc2bed.zip
Add destroyed? to ActiveRecord, include tests for polymorphic urls for destroyed objects and refactor mime responds tests and documentation.
Diffstat (limited to 'actionpack/lib/action_controller/metal/mime_responds.rb')
-rw-r--r--actionpack/lib/action_controller/metal/mime_responds.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index 837496e477..02a88437e3 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -330,6 +330,37 @@ module ActionController #:nodoc:
# In this case, since @person.destroyed? returns true, polymorphic urls will
# redirect to the collection url, instead of the resource url.
#
+ # === Nested resources
+ #
+ # respond_with also works with nested resources, you just need to pass them
+ # as you do in form_for and polymorphic_url. Consider the project has many
+ # tasks example. The create action for TasksController would be like:
+ #
+ # def create
+ # @project = Project.find(params[:project_id])
+ # @task = @project.comments.build(params[:task])
+ # @task.save
+ # respond_with([@project, @task])
+ # end
+ #
+ # Namespaced and singleton resources requires a symbol to be given, as in
+ # polymorphic urls. If a project has one manager with has many tasks, it
+ # should be invoked as:
+ #
+ # respond_with([@project, :manager, @task])
+ #
+ # Be sure to check polymorphic_url documentation. The only occasion you will
+ # need to give clear input to respond_with is in DELETE verbs for singleton
+ # resources. In such cases, the collection url does not exist, so you need
+ # to supply the destination url after delete:
+ #
+ # def destroy
+ # @project = Project.find(params[:project_id])
+ # @manager = @project.manager
+ # @manager.destroy
+ # respond_with([@project, @manager], :location => root_url)
+ # end
+ #
def respond_with(resource, options={}, &block)
respond_to(&block)
rescue ActionView::MissingTemplate => e