aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorMatt Jones <al2o3cr@gmail.com>2009-02-24 10:38:07 -0600
committerJoshua Peek <josh@joshpeek.com>2009-02-24 10:38:07 -0600
commitb35562f432d0807517a614a540026c2fc557e2ac (patch)
tree5b6b797ce782ced42463793c7d1aa6d293d2b8d1 /actionpack/lib/action_controller
parent53cd102b39eb62567298430cbd94e40dd78d46a0 (diff)
downloadrails-b35562f432d0807517a614a540026c2fc557e2ac.tar.gz
rails-b35562f432d0807517a614a540026c2fc557e2ac.tar.bz2
rails-b35562f432d0807517a614a540026c2fc557e2ac.zip
correctly handle layouts for AJAX requests and regular js files [#2052 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/layout.rb21
1 files changed, 14 insertions, 7 deletions
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index a0db7acf72..ccd9605562 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -207,21 +207,23 @@ module ActionController #:nodoc:
when Proc then layout.call(self)
else layout
end
-
- find_layout(active_layout, @template.template_format) if active_layout
+
+ find_layout(active_layout, default_template_format) if active_layout
end
private
def default_layout #:nodoc:
- layout = self.class.read_inheritable_attribute(:layout) unless default_template_format == :js
+ layout = self.class.read_inheritable_attribute(:layout)
return layout unless self.class.read_inheritable_attribute(:auto_layout)
find_layout(layout, default_template_format)
rescue ActionView::MissingTemplate
nil
end
- def find_layout(layout, *formats) #:nodoc:
- view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", *formats)
+ def find_layout(layout, format) #:nodoc:
+ view_paths.find_template(layout.to_s =~ /layouts\// ? layout : "layouts/#{layout}", format, false)
+ rescue ActionView::MissingTemplate
+ raise if Mime::Type.lookup_by_extension(format.to_s).html?
end
def pick_layout(options)
@@ -258,7 +260,12 @@ module ActionController #:nodoc:
template = options[:template] || default_template(options[:action])
if options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty?
begin
- !self.view_paths.find_template(template, default_template_format).exempt_from_layout?
+ template_object = self.view_paths.find_template(template, default_template_format)
+ # this restores the behavior from 2.2.2, where response.template.template_format was reset
+ # to :html for :js requests with a matching html template.
+ # see v2.2.2, ActionView::Base, lines 328-330
+ @real_format = :html if response.template.template_format == :js && template_object.format == "html"
+ !template_object.exempt_from_layout?
rescue ActionView::MissingTemplate
true
end
@@ -268,7 +275,7 @@ module ActionController #:nodoc:
end
def default_template_format
- response.template.template_format
+ @real_format || response.template.template_format
end
end
end