diff options
Diffstat (limited to 'actionpack/lib')
-rwxr-xr-x | actionpack/lib/action_controller/base.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/mime_responds.rb | 14 | ||||
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 2 |
3 files changed, 11 insertions, 7 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 2c91266f6f..1ceb58711b 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -27,6 +27,8 @@ module ActionController #:nodoc: end class MissingFile < ActionControllerError #:nodoc: end + class RenderError < ActionControllerError #:nodoc: + end class SessionOverflowError < ActionControllerError #:nodoc: DEFAULT_MESSAGE = 'Your session data is larger than the data column in which it is to be stored. You must increase the size of your data column if you intend to store large data.' diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb index fd9af05905..21905b26c8 100644 --- a/actionpack/lib/action_controller/mime_responds.rb +++ b/actionpack/lib/action_controller/mime_responds.rb @@ -108,11 +108,9 @@ module ActionController #:nodoc: end class Responder #:nodoc: - DEFAULT_BLOCKS = { - :html => 'Proc.new { render }', - :js => 'Proc.new { render :action => "#{action_name}.rjs" }', - :xml => 'Proc.new { render :action => "#{action_name}.rxml" }' - } + DEFAULT_BLOCKS = [:html, :js, :xml].inject({}) do |blocks, ext| + blocks.update ext => %(Proc.new { render :action => "\#{action_name}.r#{ext}" }) + end def initialize(block_binding) @block_binding = block_binding @@ -134,7 +132,11 @@ module ActionController #:nodoc: if block_given? @responses[mime_type] = block else - @responses[mime_type] = eval(DEFAULT_BLOCKS[mime_type.to_sym], @block_binding) + if source = DEFAULT_BLOCKS[mime_type.to_sym] + @responses[mime_type] = eval(source, @block_binding) + else + raise ActionController::RenderError, "Expected a block but none was given for custom mime handler #{mime_type}" + end end end diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index dccc32bb91..f2b8e32546 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -34,7 +34,7 @@ module Mime def register(string, symbol, synonyms = []) Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, synonyms) SET << Mime.send(:const_get, symbol.to_s.upcase) - LOOKUP[string] = EXTENSION_LOOKUP[symbol.to_s] = SET.last + LOOKUP[string] = EXTENSION_LOOKUP[symbol.to_s] = SET.last end def parse(accept_header) |