Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11140 (closed defect: fixed)

Opened 5 months ago

Last modified 4 months ago

[PATCH] MimeResponds::Responder#any should really handle any

Reported by: jaw6 Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: verified
Cc:

Description

It seems to me that Responder#any doesn't actually do what it seems like it should: it should be possible to use Responder#any in respond_to blocks, without having to be required to pass explicit types for all imaginable types, eg, as a catch-all for any requested mime-types not already specified.

For example, in restful_authentication, this is supposed to require non-browser agents to authenticate with http basic:

def access_denied
  respond_to do |format|
    format.html do
      store_location
      redirect_to new_<%= controller_singular_name %>_path
    end
    format.any do
      request_http_basic_authentication 'Web Password'
    end
  end
end

It doesn't work, though, because #any currently requires a list of types. This seems redundant, if it's the intended behavior (if I knew what types, why would I be using any?)

The attached patch (with tests) allows a "naked any", while preserving compatibility with the previous signature.

Attachments

mime_responds_diff (2.5 kB) - added by jaw6 on 02/17/08 16:02:19.
The Patch
mime_responds2.diff (2.5 kB) - added by jaw6 on 03/05/08 16:14:40.

Change History

02/17/08 16:02:19 changed by jaw6

  • attachment mime_responds_diff added.

The Patch

02/18/08 12:11:46 changed by spif

+1

02/18/08 12:14:18 changed by smn

+1

02/18/08 23:11:46 changed by leftist

+1

02/19/08 10:01:14 changed by jaw6

  • keywords set to verified.

03/04/08 20:09:35 changed by lifofifo

63 	-        @responses[mime_type] = Proc.new do
64 	+        @responses[mime_type] ||= Proc.new do
65 	           @response.template.template_format = mime_type.to_sym
66 	           @response.content_type = mime_type.to_s
67 	           block_given? ? block.call : @controller.send(:render, :action => @controller.action_name)
68 	         end
69 	+        # raise @responses.inspect

You might want to remove the commented debug message :-)

Also, what's the reason for caching @responses[mime_type] ?

03/05/08 16:13:51 changed by jaw6

Okay, new patch coming soon :-)

Caching: You mean the = ? Without this, any() will write-over more specific response types, in cases where the format is broad (eg, there's no "format=html") but assumed to be HTML.

03/05/08 16:14:40 changed by jaw6

  • attachment mime_responds2.diff added.

03/05/08 16:43:45 changed by lifofifo

Ah, cool. Makes sense. Thanks for explanation.

03/07/08 11:17:10 changed by pratik

  • status changed from new to closed.
  • resolution set to fixed.

(In [8987]) Make MimeResponds::Responder#any work without explicit types. Closes #11140 [jaw6]