aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/layout.rb22
-rw-r--r--actionpack/test/controller/new_render_test.rb13
-rw-r--r--actionpack/test/controller/send_file_test.rb2
4 files changed, 33 insertions, 6 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 63bfaef4d3..9bac83a0e6 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* render(:text), render(:partial), and render(:nothing) always default to :layout => false. This also fixes send_file, which was applying a layout if one existed for the current action.
+
* verify with :redirect_to won't redirect if a redirect or render has already been performed #1350
* render(:partial => true) is identical to the behavior of the deprecated render_partial()
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index e7e8d3b834..d4ec7744aa 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -144,12 +144,12 @@ module ActionController #:nodoc:
#
# If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above.
# Some times you'll have exceptions, though, where one action wants to use a different layout than the rest of the controller.
- # This is possible using <tt>render_with_layout</tt> method. It's just a bit more manual work as you'll have to supply fully
+ # This is possible using the <tt>render</tt> method. It's just a bit more manual work as you'll have to supply fully
# qualified template and layout names as this example shows:
#
# class WeblogController < ActionController::Base
# def help
- # render_with_layout "help/index", "200", "layouts/help"
+ # render :file => "help/index", :layout => "layouts/help"
# end
# end
#
@@ -203,7 +203,8 @@ module ActionController #:nodoc:
end
def render_with_a_layout(options = {}, deprecated_status = nil, deprecated_layout = nil) #:nodoc:
- if (layout = pick_layout(options, deprecated_layout)) && options.is_a?(Hash) && options[:text]
+ options = render_with_a_layout_options(options)
+ if (layout = pick_layout(options, deprecated_layout))
logger.info("Rendering #{options[:template]} within #{layout}") unless logger.nil?
@content_for_layout = render_with_no_layout(options.merge(:layout => false))
@@ -217,8 +218,19 @@ module ActionController #:nodoc:
end
private
+ def render_with_a_layout_options(options)
+ return options unless options.is_a?(Hash)
+ case
+ when options[:text], options[:partial], options[:nothing]
+ # by default, :text, :partial, and :nothing never use a layout
+ { :layout => false }.merge(options)
+ else
+ options
+ end
+ end
+
def pick_layout(options = {}, deprecated_layout = nil)
- return deprecated_layout if !deprecated_layout.nil? || (options.is_a?(Hash) && options[:nothing])
+ return deprecated_layout if !deprecated_layout.nil?
if options.is_a?(Hash)
case options[:layout]
@@ -246,4 +258,4 @@ module ActionController #:nodoc:
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb
index ad1415aca3..3d1e6e794b 100644
--- a/actionpack/test/controller/new_render_test.rb
+++ b/actionpack/test/controller/new_render_test.rb
@@ -75,6 +75,10 @@ class TestController < ActionController::Base
render :partial => true
end
+ def partial_only_with_layout
+ render :partial => "partial_only", :layout => nil
+ end
+
def hello_in_a_string
@customers = [ Customer.new("david"), Customer.new("mary") ]
render :text => "How's there? #{render_to_string("test/list")}"
@@ -89,7 +93,9 @@ class TestController < ActionController::Base
private
def determine_layout
case action_name
- when "layout_test", "rendering_without_layout", "rendering_nothing_on_layout"
+ when "layout_test", "rendering_without_layout",
+ "rendering_nothing_on_layout", "render_text_hello_world",
+ "partial_only", "partial_only_with_layout"
"layouts/standard"
when "builder_layout_test"
"layouts/builder"
@@ -219,6 +225,11 @@ class RenderTest < Test::Unit::TestCase
assert_equal "only partial", @response.body
end
+ def test_partial_only_with_layout
+ get :partial_only_with_layout
+ assert_equal "<html>only partial</html>", @response.body
+ end
+
def test_render_to_string
get :hello_in_a_string
assert_equal "How's there? Hello: davidHello: mary", @response.body
diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb
index d18d15b18a..b7674bda60 100644
--- a/actionpack/test/controller/send_file_test.rb
+++ b/actionpack/test/controller/send_file_test.rb
@@ -10,6 +10,7 @@ end
class SendFileController < ActionController::Base
include TestFileUtils
+ layout "layouts/standard" # to make sure layouts don't interfere
attr_writer :options
def options() @options ||= {} end
@@ -20,6 +21,7 @@ class SendFileController < ActionController::Base
def rescue_action(e) raise end
end
+SendFileController.template_root = File.dirname(__FILE__) + "/../fixtures/"
class SendFileTest < Test::Unit::TestCase
include TestFileUtils