From 6351e0a541698bdaca348ad78bc9f7b25f6d56d6 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 12 Apr 2007 20:25:32 +0000 Subject: The default respond_to blocks don't set a specific extension anymore, so that both 'show.rjs' and 'show.js.rjs' will work. [Rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6517 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/base.rb | 2 +- actionpack/lib/action_controller/mime_responds.rb | 21 +++++++++++++++------ actionpack/lib/action_controller/request.rb | 4 +++- 3 files changed, 19 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 7262472586..8e01af406c 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1225,7 +1225,7 @@ module ActionController #:nodoc: def assert_existence_of_template_file(template_name) unless template_exists?(template_name) || ignore_missing_templates - full_template_path = @template.send(:full_template_path, template_name, "#{@template.send(:template_format)}.erb") + full_template_path = template_name.include?('.') ? template_name : @template.send(:full_template_path, template_name, "#{@template.send(:template_format)}.erb") template_type = (template_name =~ /layouts/i) ? 'layout' : 'template' raise(MissingTemplate, "Missing #{template_type} #{full_template_path}") end diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb index e4d1dbbccc..0b4c4b6793 100644 --- a/actionpack/lib/action_controller/mime_responds.rb +++ b/actionpack/lib/action_controller/mime_responds.rb @@ -107,11 +107,17 @@ module ActionController #:nodoc: end class Responder #:nodoc: - default_block_format = %(Proc.new { render :action => "\#{action_name}%s", :content_type => Mime::%s }) - DEFAULT_BLOCKS = {} - DEFAULT_BLOCKS[:html] = default_block_format % ['', 'HTML'] - DEFAULT_BLOCKS[:js] = default_block_format % ['.js.rjs', 'JS'] - DEFAULT_BLOCKS[:xml] = default_block_format % ['.xml.builder', 'XML'] + default_block_format = <<-END + Proc.new { + @template.template_format = '%s' + render :action => "\#{action_name}", :content_type => Mime::%s + } + END + + DEFAULT_BLOCKS = [:html, :js, :xml].inject({}) do |memo, ext| + default_block = default_block_format % [ext, ext.to_s.upcase] + memo.update(ext => default_block) + end def initialize(block_binding) @block_binding = block_binding @@ -132,7 +138,10 @@ module ActionController #:nodoc: if block_given? @responses[mime_type] = Proc.new do - eval "response.content_type = '#{mime_type.to_s}'", @block_binding + eval <<-END, @block_binding + @template.template_format = '#{mime_type.to_sym}' + response.content_type = '#{mime_type.to_s}' + END block.call end else diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 5279315023..eed1563aba 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -9,6 +9,8 @@ module ActionController # such as { 'RAILS_ENV' => 'production' }. attr_reader :env + attr_accessor :format + # Returns the HTTP request method as a lowercase symbol (:get, for example). Note, HEAD is returned as :get # since the two are supposedly to be functionaly equivilent for all purposes except that HEAD won't return a response # body (which Rails also takes care of elsewhere). @@ -91,7 +93,7 @@ module ActionController # GET /posts/5.xhtml | request.format => Mime::HTML # GET /posts/5 | request.format => request.accepts.first (usually Mime::HTML for browsers) def format - parameters[:format] ? Mime::Type.lookup_by_extension(parameters[:format]) : accepts.first + @format ||= parameters[:format] ? Mime::Type.lookup_by_extension(parameters[:format]) : accepts.first end # Returns true if the request's "X-Requested-With" header contains -- cgit v1.2.3