Permalink
Browse files

Cure some ills discovered with the refactoring

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1351 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent da0c4c5 commit 2f7c5f84e4834e49001ed565cfe45f14e120613f @dhh dhh committed May 22, 2005
@@ -440,6 +440,7 @@ def action_name
# A unified replacement for the individual renders (work-in-progress).
def render(options = {}, deprecated_status = nil)
+ # puts "Rendering: #{options.inspect}"
raise DoubleRenderError, "Can only render or redirect once per action" if performed?
# Backwards compatibility
@@ -489,7 +490,7 @@ def render(options = {}, deprecated_status = nil)
end
# Returns the result of the render as a string.
- def render_to_string(options) #:doc:
+ def render_to_string(options = {}) #:doc:
result = render(options)
erase_render_results
return result
@@ -538,7 +539,7 @@ def redirect_to(options = {}, *parameters_for_method_reference) #:doc:
case options
when %r{^\w+://.*}
raise DoubleRenderError, "Can only render or redirect once per action" if performed?
- logger.info("Redirected to #{url}") unless logger.nil?
+ logger.info("Redirected to #{options}") unless logger.nil?
@response.redirect(options)
@performed_redirect = true
@@ -26,7 +26,7 @@ def render_template(template, status = nil, type = "rhtml") #:doc:
# considerably faster than rendering through the template engine.
# Use block for response body if provided (useful for deferred rendering or streaming output).
def render_text(text = nil, status = nil) #:doc:
- render(:text => text, :status => status) { yield }
+ render :text => text, :status => status
end
# Renders an empty response that can be used when the request is only interested in triggering an effect. Do note that good
@@ -51,6 +51,14 @@ def render_partial_collection(partial_name, collection, partial_spacer_template
render :partial => partial_name, :collection => collection, :spacer_template => partial_spacer_template, :locals => local_assigns
end
+ def render_with_layout(template_name = default_template_name, status = nil, layout = nil) #:nodoc:
+ render :template => template_name, :status => status, :layout => layout
+ end
+
+ def render_without_layout(template_name = default_template_name, status = nil) #:nodoc:
+ render :template => template_name, :status => status, :layout => false
+ end
+
# Deprecated in favor of calling redirect_to directly with the path.
def redirect_to_path(path) #:doc:
@@ -3,8 +3,8 @@ module Layout #:nodoc:
def self.append_features(base)
super
base.class_eval do
- alias_method :render_without_layout, :render
- alias_method :render, :render_with_layout
+ alias_method :render_with_no_layout, :render
+ alias_method :render, :render_with_a_layout
class << self
alias_method :inherited_without_layout, :inherited
@@ -202,43 +202,35 @@ def active_layout(passed_layout = nil)
active_layout.include?("/") ? active_layout : "layouts/#{active_layout}" if active_layout
end
- def xrender_with_layout(template_name = default_template_name, status = nil, layout = nil) #:nodoc:
- if layout ||= active_layout and action_has_layout?
- add_variables_to_assigns
- logger.info("Rendering #{template_name} within #{layout}") unless logger.nil?
- @content_for_layout = @template.render_file(template_name, true)
- render_without_layout(layout, status)
- else
- render_without_layout(template_name, status)
- end
- 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]
+ logger.info("Rendering #{options[:template]} within #{layout}") unless logger.nil?
- def render_with_layout(options = {}, deprecated_status = nil, deprecated_layout = nil)
- if (layout = active_layout_for_r(options, deprecated_layout)) && options[:text]
- add_variables_to_assigns
- logger.info("Rendering #{template_name} within #{layout}") unless logger.nil?
+ @content_for_layout = render_with_no_layout(options.merge(:layout => false))
+ erase_render_results
- @content_for_layout = render_without_layout(options)
add_variables_to_assigns
-
- erase_render_results
- render_without_layout(options.merge({ :text => @template.render_file(layout, true), :status => options[:status] || deprecated_status }))
+ render_with_no_layout(options.merge({ :text => @template.render_file(layout, true), :status => options[:status] || deprecated_status }))
else
- render_without_layout(options, deprecated_status)
+ render_with_no_layout(options, deprecated_status)
end
end
private
- def active_layout_for_r(options = {}, deprecated_layout = nil)
+ def pick_layout(options = {}, deprecated_layout = nil)
return deprecated_layout unless deprecated_layout.nil?
- case options[:layout]
- when FalseClass
- nil
- when NilClass
- active_layout if action_has_layout?
- else
- active_layout(options[:layout])
+ if options.is_a?(Hash)
+ case options[:layout]
+ when FalseClass
+ nil
+ when NilClass
+ active_layout if action_has_layout?
+ else
+ active_layout(options[:layout])
+ end
+ else
+ (deprecated_layout || active_layout) if action_has_layout?
end
end
@@ -8,7 +8,7 @@ def initialize
end
def redirect(to_url, permanently = false)
- @headers["Status"] ||= "302 Found"
+ @headers["Status"] = "302 Found" unless @headers["Status"] == "301 Moved Permanently"
@headers["location"] = to_url
@body = "<html><body>You are being <a href=\"#{to_url}\">redirected</a>.</body></html>"
@@ -77,7 +77,7 @@ def verify_action(options) #:nodoc:
if prereqs_invalid
flash.update(options[:add_flash]) if options[:add_flash]
- redirect_to(options[:redirect_to])
+ redirect_to(options[:redirect_to]) if options[:redirect_to]
return false
end

0 comments on commit 2f7c5f8

Please sign in to comment.