From 3b40a5d83db90534b3cb61f4dc25547f501e4775 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 3 Dec 2013 22:23:11 -0200 Subject: Improve a couple exception messages related to variants and mime types Avoid one-liner conditionals when they are too big. Avoid concatenating strings to build error messages. Improve messages a bit. --- actionpack/lib/abstract_controller/collector.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/abstract_controller/collector.rb') diff --git a/actionpack/lib/abstract_controller/collector.rb b/actionpack/lib/abstract_controller/collector.rb index f7a309c26c..ddd56b354a 100644 --- a/actionpack/lib/abstract_controller/collector.rb +++ b/actionpack/lib/abstract_controller/collector.rb @@ -23,15 +23,17 @@ module AbstractController protected def method_missing(symbol, &block) - mime_const = symbol.upcase - - 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," + - "be sure to nest your variant response within a format response: format.html" + - "{ |html| html.tablet { ..." unless Mime.const_defined?(mime_const) + const_name = symbol.upcase + + unless Mime.const_defined?(const_name) + 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, " \ + "be sure to nest your variant response within a format response: " \ + "format.html { |html| html.tablet { ... } }" + end - mime_constant = Mime.const_get(mime_const) + mime_constant = Mime.const_get(const_name) if Mime::SET.include?(mime_constant) AbstractController::Collector.generate_method_for_mime(mime_constant) -- cgit v1.2.3