Make sure render :update support the options hash. Closes #11088 [ernesto.jimenez]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8862 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
11787b802a
commit
46356100d1
@ -834,14 +834,16 @@ def append_view_path(path)
|
||||
# All renders take the :status and :location options and turn them into headers. They can even be used together:
|
||||
#
|
||||
# render :xml => post.to_xml, :status => :created, :location => post_url(post)
|
||||
def render(options = nil, &block) #:doc:
|
||||
def render(options = nil, extra_options = {}, &block) #:doc:
|
||||
raise DoubleRenderError, "Can only render or redirect once per action" if performed?
|
||||
|
||||
if options.nil?
|
||||
return render_for_file(default_template_name, nil, true)
|
||||
elsif !extra_options.is_a?(Hash)
|
||||
raise RenderError, "You called render with invalid options : #{options}, #{extra_options}"
|
||||
else
|
||||
if options == :update
|
||||
options = { :update => true }
|
||||
options = extra_options.merge({ :update => true })
|
||||
elsif !options.is_a?(Hash)
|
||||
raise RenderError, "You called render with invalid options : #{options}"
|
||||
end
|
||||
@ -910,7 +912,7 @@ def render(options = nil, &block) #:doc:
|
||||
|
||||
generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block)
|
||||
response.content_type = Mime::JS
|
||||
render_for_text(generator.to_s)
|
||||
render_for_text(generator.to_s, options[:status])
|
||||
|
||||
elsif options[:nothing]
|
||||
# Safari doesn't pass the headers of the return if the response is zero length
|
||||
|
@ -41,14 +41,14 @@ def silence
|
||||
end
|
||||
|
||||
protected
|
||||
def render_with_benchmark(options = nil, deprecated_status = nil, &block)
|
||||
def render_with_benchmark(options = nil, extra_options = {}, &block)
|
||||
unless logger
|
||||
render_without_benchmark(options, &block)
|
||||
render_without_benchmark(options, extra_options, &block)
|
||||
else
|
||||
db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
|
||||
|
||||
render_output = nil
|
||||
@rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, &block) }.real
|
||||
@rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, extra_options, &block) }.real
|
||||
|
||||
if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
|
||||
@db_rt_before_render = db_runtime
|
||||
|
@ -243,7 +243,7 @@ def active_layout(passed_layout = nil)
|
||||
end
|
||||
|
||||
protected
|
||||
def render_with_a_layout(options = nil, &block) #:nodoc:
|
||||
def render_with_a_layout(options = nil, extra_options = {}, &block) #:nodoc:
|
||||
template_with_options = options.is_a?(Hash)
|
||||
|
||||
if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options))
|
||||
@ -252,7 +252,7 @@ def render_with_a_layout(options = nil, &block) #:nodoc:
|
||||
options = options.merge :layout => false if template_with_options
|
||||
logger.info("Rendering template within #{layout}") if logger
|
||||
|
||||
content_for_layout = render_with_no_layout(options, &block)
|
||||
content_for_layout = render_with_no_layout(options, extra_options, &block)
|
||||
erase_render_results
|
||||
add_variables_to_assigns
|
||||
@template.instance_variable_set("@content_for_layout", content_for_layout)
|
||||
@ -260,7 +260,7 @@ def render_with_a_layout(options = nil, &block) #:nodoc:
|
||||
status = template_with_options ? options[:status] : nil
|
||||
render_for_text(@template.render_file(layout, true), status)
|
||||
else
|
||||
render_with_no_layout(options, &block)
|
||||
render_with_no_layout(options, extra_options, &block)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -61,6 +61,12 @@ def render_custom_code
|
||||
render :text => "hello world", :status => 404
|
||||
end
|
||||
|
||||
def render_custom_code_rjs
|
||||
render :update, :status => 404 do |page|
|
||||
page.replace :foo, :partial => 'partial'
|
||||
end
|
||||
end
|
||||
|
||||
def render_text_with_nil
|
||||
render :text => nil
|
||||
end
|
||||
@ -288,6 +294,12 @@ def test_render_custom_code
|
||||
assert_equal 'hello world', @response.body
|
||||
end
|
||||
|
||||
def test_render_custom_code_rjs
|
||||
get :render_custom_code_rjs
|
||||
assert_response 404
|
||||
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
||||
end
|
||||
|
||||
def test_render_text_with_nil
|
||||
get :render_text_with_nil
|
||||
assert_response 200
|
||||
|
Loading…
Reference in New Issue
Block a user