diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-05-31 18:52:24 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-05-31 18:52:24 +0000 |
commit | f9cd92f4ee49c689f25dbe7da008fb298a5feb4f (patch) | |
tree | 1498f6f638177ff53f99fb85cb89dc3c01c884e9 /actionpack/lib | |
parent | e7fe1c47baf89522617b67e96b701ee916adcb88 (diff) | |
download | rails-f9cd92f4ee49c689f25dbe7da008fb298a5feb4f.tar.gz rails-f9cd92f4ee49c689f25dbe7da008fb298a5feb4f.tar.bz2 rails-f9cd92f4ee49c689f25dbe7da008fb298a5feb4f.zip |
Added interrogation of params[:format] to determine Accept type. If :format is specified and matches a declared extension, like "rss" or "xml", that mime type will be put in front of the accept handler. This means you can link to the same action from different extensions and use that fact to determine output [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4384 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/mime_responds.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 17 |
2 files changed, 23 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb index ff4837896c..e1e6790381 100644 --- a/actionpack/lib/action_controller/mime_responds.rb +++ b/actionpack/lib/action_controller/mime_responds.rb @@ -110,7 +110,12 @@ module ActionController #:nodoc: def initialize(block_binding) @block_binding = block_binding - @mime_type_priority = eval("request.accepts", block_binding) + @mime_type_priority = eval( + "(params[:format] && Mime::EXTENSION_LOOKUP[params[:format]]) ? " + + "[ Mime::EXTENSION_LOOKUP[params[:format]] ] : request.accepts", + block_binding + ) + @order = [] @responses = {} end diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index 30cea88a44..ff65e18e44 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -119,6 +119,7 @@ module Mime ATOM = Type.new "application/atom+xml", :atom YAML = Type.new "application/x-yaml", :yaml, %w( text/yaml ) + LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) } LOOKUP["*/*"] = ALL @@ -139,4 +140,20 @@ module Mime LOOKUP["application/rss+xml"] = RSS LOOKUP["application/atom+xml"] = ATOM + + + EXTENSION_LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) } + + EXTENSION_LOOKUP["html"] = HTML + EXTENSION_LOOKUP["xhtml"] = HTML + + EXTENSION_LOOKUP["xml"] = XML + + EXTENSION_LOOKUP["js"] = JS + + EXTENSION_LOOKUP["yml"] = YAML + EXTENSION_LOOKUP["yaml"] = YAML + + EXTENSION_LOOKUP["rss"] = RSS + EXTENSION_LOOKUP["atom"] = ATOM end
\ No newline at end of file |