Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1369 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit f57ee365e154ce6d15cd168112d94a9a8ff27094 1 parent 6132606
Jamis Buck jamis authored
2  actionpack/CHANGELOG
View
@@ -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()
22 actionpack/lib/action_controller/layout.rb
View
@@ -144,12 +144,12 @@ class << self
#
# 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 @@ def active_layout(passed_layout = nil)
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 @@ def render_with_a_layout(options = {}, deprecated_status = nil, deprecated_layou
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 @@ def action_has_layout?
end
end
end
-end
+end
13 actionpack/test/controller/new_render_test.rb
View
@@ -75,6 +75,10 @@ def partial_only
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 @@ def rescue_action(e) raise end
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 @@ def test_partial_only
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
2  actionpack/test/controller/send_file_test.rb
View
@@ -10,6 +10,7 @@ def file_data() File.open(file_path, 'rb') { |f| f.read } 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 @@ def data() send_data(file_data, options) end
def rescue_action(e) raise end
end
+SendFileController.template_root = File.dirname(__FILE__) + "/../fixtures/"
class SendFileTest < Test::Unit::TestCase
include TestFileUtils
Please sign in to comment.
Something went wrong with that request. Please try again.