aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller/collector.rb
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2015-10-04 22:14:04 -0700
committerJeremy Daer <jeremydaer@gmail.com>2015-10-06 11:29:30 -0700
commit565094a8b5cdfa158fef6ae75252fd98a4ba8fe4 (patch)
tree78cc5fc25b114c26e14d855370e16139dbd4b679 /actionpack/lib/abstract_controller/collector.rb
parent5b69e30622de27e8010fd8cb32a97b5f0fe194e2 (diff)
downloadrails-565094a8b5cdfa158fef6ae75252fd98a4ba8fe4.tar.gz
rails-565094a8b5cdfa158fef6ae75252fd98a4ba8fe4.tar.bz2
rails-565094a8b5cdfa158fef6ae75252fd98a4ba8fe4.zip
Use `Mime[:foo]` instead of `Mime::Type[:FOO]` for back compat
Rails 4.x and earlier didn't support `Mime::Type[:FOO]`, so libraries that support multiple Rails versions would've had to feature-detect whether to use `Mime::Type[:FOO]` or `Mime::FOO`. `Mime[:foo]` has been around for ages to look up registered MIME types by symbol / extension, though, so libraries and plugins can safely switch to that without breaking backward- or forward-compatibility. Note: `Mime::ALL` isn't a real MIME type and isn't registered for lookup by type or extension, so it's not available as `Mime[:all]`. We use it internally as a wildcard for `respond_to` negotiation. If you use this internal constant, continue to reference it with `Mime::ALL`. Ref. efc6dd550ee49e7e443f9d72785caa0f240def53
Diffstat (limited to 'actionpack/lib/abstract_controller/collector.rb')
-rw-r--r--actionpack/lib/abstract_controller/collector.rb13
1 files changed, 4 insertions, 9 deletions
diff --git a/actionpack/lib/abstract_controller/collector.rb b/actionpack/lib/abstract_controller/collector.rb
index 3b5128cda5..55654be224 100644
--- a/actionpack/lib/abstract_controller/collector.rb
+++ b/actionpack/lib/abstract_controller/collector.rb
@@ -4,11 +4,10 @@ module AbstractController
module Collector
def self.generate_method_for_mime(mime)
sym = mime.is_a?(Symbol) ? mime : mime.to_sym
- const = sym.upcase
class_eval <<-RUBY, __FILE__, __LINE__ + 1
- def #{sym}(*args, &block) # def html(*args, &block)
- custom(Mime::Type[:#{const}], *args, &block) # custom(Mime::Type[:HTML], *args, &block)
- end # end
+ def #{sym}(*args, &block)
+ custom(Mime[:#{sym}], *args, &block)
+ end
RUBY
end
@@ -23,9 +22,7 @@ module AbstractController
protected
def method_missing(symbol, &block)
- const_name = symbol.upcase
-
- unless Mime::Type.registered?(const_name)
+ unless mime_constant = Mime[symbol]
raise NoMethodError, "To respond to a custom format, register it as a MIME type first: " \
"http://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. " \
"If you meant to respond to a variant like :tablet or :phone, not a custom format, " \
@@ -33,8 +30,6 @@ module AbstractController
"format.html { |html| html.tablet { ... } }"
end
- mime_constant = Mime::Type[const_name]
-
if Mime::SET.include?(mime_constant)
AbstractController::Collector.generate_method_for_mime(mime_constant)
send(symbol, &block)