mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Ensure strings given to render with slash are rendered relative to the configured _prefix.
This commit is contained in:
@@ -98,18 +98,9 @@ module AbstractController
|
||||
_view_paths
|
||||
end
|
||||
|
||||
# Normalize options, by converting render "foo" to render :template => "foo"
|
||||
# and render "/foo" to render :file => "/foo".
|
||||
def _normalize_options(action=nil, options={})
|
||||
case action
|
||||
when Hash
|
||||
options, action = action, nil
|
||||
when String
|
||||
key = (action.index("/") == 0 ? :file : :template)
|
||||
options.merge!(key => action)
|
||||
end
|
||||
|
||||
options
|
||||
# The prefix used in render "foo" shortcuts.
|
||||
def _prefix
|
||||
controller_path
|
||||
end
|
||||
|
||||
# Return a string representation of a Rack-compatible response body.
|
||||
@@ -126,6 +117,28 @@ module AbstractController
|
||||
|
||||
private
|
||||
|
||||
# Normalize options, by converting render "foo" to render :template => "prefix/foo"
|
||||
# and render "/foo" to render :file => "/foo".
|
||||
def _normalize_options(action=nil, options={})
|
||||
case action
|
||||
when Hash
|
||||
options, action = action, nil
|
||||
when String, Symbol
|
||||
action = action.to_s
|
||||
case action.index("/")
|
||||
when NilClass
|
||||
options[:_prefix] = _prefix
|
||||
options[:_template_name] = action
|
||||
when 0
|
||||
options[:file] = action
|
||||
else
|
||||
options[:template] = action
|
||||
end
|
||||
end
|
||||
|
||||
options
|
||||
end
|
||||
|
||||
# Take in a set of options and determine the template to render
|
||||
#
|
||||
# ==== Options
|
||||
|
||||
@@ -81,28 +81,5 @@ module ActionController
|
||||
filter << block if block
|
||||
filter
|
||||
end
|
||||
|
||||
def _normalize_options(action=nil, options={}, &blk)
|
||||
case action
|
||||
when NilClass
|
||||
when Hash, String
|
||||
options = super
|
||||
when Symbol
|
||||
options.merge! :action => action
|
||||
else
|
||||
options.merge! :partial => action
|
||||
end
|
||||
|
||||
if options.key?(:action) && options[:action].to_s.index("/")
|
||||
options[:template] = options.delete(:action)
|
||||
end
|
||||
|
||||
if options[:status]
|
||||
options[:status] = Rack::Utils.status_code(options[:status])
|
||||
end
|
||||
|
||||
options[:update] = blk if block_given?
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,18 +25,6 @@ module ActionController
|
||||
end
|
||||
|
||||
private
|
||||
def _prefix
|
||||
controller_path
|
||||
end
|
||||
|
||||
def _determine_template(options)
|
||||
if (options.keys & [:partial, :file, :template, :text, :inline]).empty?
|
||||
options[:_template_name] ||= options[:action]
|
||||
options[:_prefix] = _prefix
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def _render_partial(options)
|
||||
options[:partial] = action_name if options[:partial] == true
|
||||
@@ -54,5 +42,29 @@ module ActionController
|
||||
self.content_type = content_type if content_type
|
||||
self.headers["Location"] = url_for(location) if location
|
||||
end
|
||||
|
||||
def _normalize_options(action=nil, options={}, &blk)
|
||||
case action
|
||||
when NilClass
|
||||
when Hash
|
||||
options = super(action.delete(:action), action)
|
||||
when String, Symbol
|
||||
options = super
|
||||
else
|
||||
options.merge! :partial => action
|
||||
end
|
||||
|
||||
if (options.keys & [:partial, :file, :template, :text, :inline]).empty?
|
||||
options[:_template_name] ||= options[:action]
|
||||
options[:_prefix] = _prefix
|
||||
end
|
||||
|
||||
if options[:status]
|
||||
options[:status] = Rack::Utils.status_code(options[:status])
|
||||
end
|
||||
|
||||
options[:update] = blk if block_given?
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,9 +6,16 @@ module AbstractController
|
||||
class ControllerRenderer < AbstractController::Base
|
||||
include AbstractController::Rendering
|
||||
|
||||
def _prefix
|
||||
"renderer"
|
||||
end
|
||||
|
||||
self.view_paths = [ActionView::FixtureResolver.new(
|
||||
"default.erb" => "With Default",
|
||||
"template.erb" => "With Template",
|
||||
"renderer/string.erb" => "With String",
|
||||
"renderer/symbol.erb" => "With Symbol",
|
||||
"string/with_path.erb" => "With String With Path",
|
||||
"some/file.erb" => "With File",
|
||||
"template_name.erb" => "With Template Name"
|
||||
)]
|
||||
@@ -33,8 +40,16 @@ module AbstractController
|
||||
render
|
||||
end
|
||||
|
||||
def shortcut
|
||||
render "template"
|
||||
def string
|
||||
render "string"
|
||||
end
|
||||
|
||||
def string_with_path
|
||||
render "string/with_path"
|
||||
end
|
||||
|
||||
def symbol
|
||||
render :symbol
|
||||
end
|
||||
|
||||
def template_name
|
||||
@@ -77,9 +92,19 @@ module AbstractController
|
||||
assert_equal "With Default", @controller.response_body
|
||||
end
|
||||
|
||||
def test_render_template_through_shortcut
|
||||
@controller.process(:shortcut)
|
||||
assert_equal "With Template", @controller.response_body
|
||||
def test_render_string
|
||||
@controller.process(:string)
|
||||
assert_equal "With String", @controller.response_body
|
||||
end
|
||||
|
||||
def test_render_symbol
|
||||
@controller.process(:symbol)
|
||||
assert_equal "With Symbol", @controller.response_body
|
||||
end
|
||||
|
||||
def test_render_string_with_path
|
||||
@controller.process(:string_with_path)
|
||||
assert_equal "With String With Path", @controller.response_body
|
||||
end
|
||||
|
||||
def test_render_template_name
|
||||
|
||||
Reference in New Issue
Block a user