Ticket #8958: remove_all_deprecated_render_methods.3.patch
| File remove_all_deprecated_render_methods.3.patch, 35.5 kB (added by lifofifo, 1 year ago) |
|---|
-
actionpack/test/controller/render_test.rb
old new 16 16 end 17 17 18 18 def render_hello_world 19 render "test/hello_world"19 render :template => "test/hello_world" 20 20 end 21 21 22 22 def render_hello_world_from_variable 23 23 @person = "david" 24 render _text"hello #{@person}"24 render :text => "hello #{@person}" 25 25 end 26 26 27 27 def render_action_hello_world 28 render _action"hello_world"28 render :action => "hello_world" 29 29 end 30 30 31 31 def render_action_hello_world_with_symbol 32 render _action:hello_world32 render :action => :hello_world 33 33 end 34 34 35 35 def render_text_hello_world 36 render _text"hello world"36 render :text => "hello world" 37 37 end 38 38 39 39 def render_json_hello_world 40 render _json({:hello => 'world'}.to_json)40 render :json => {:hello => 'world'}.to_json 41 41 end 42 42 43 43 def render_json_hello_world_with_callback 44 render _json({:hello => 'world'}.to_json, 'alert')44 render :json => {:hello => 'world'}.to_json, :callback => 'alert' 45 45 end 46 46 47 47 def render_symbol_json … … 49 49 end 50 50 51 51 def render_custom_code 52 render _text "hello world", "404 Moved"52 render :text => "hello world", :status => 404 53 53 end 54 54 55 def render_text_appendix56 render_text "hello world"57 render_text ", goodbye!", "404 Not Found", true58 end59 60 55 def render_nothing_with_appendix 61 render _text "appended", nil, true56 render :text => "appended" 62 57 end 58 59 def render_invalid_args 60 render("test/hello") 61 end 63 62 64 63 def render_xml_hello 65 64 @name = "David" 66 render "test/hello"65 render :template => "test/hello" 67 66 end 68 67 69 68 def heading … … 75 74 end 76 75 77 76 def layout_test 78 render _action"hello_world"77 render :action => "hello_world" 79 78 end 80 79 81 80 def builder_layout_test 82 render _action"hello"81 render :action => "hello" 83 82 end 84 83 85 84 def builder_partial_test 86 render _action"hello_world_container"85 render :action => "hello_world_container" 87 86 end 88 87 89 88 def partials_list 90 89 @test_unchanged = 'hello' 91 90 @customers = [ Customer.new("david"), Customer.new("mary") ] 92 render _action"list"91 render :action => "list" 93 92 end 94 93 95 94 def partial_only 96 render _partial95 render :partial => true 97 96 end 98 97 99 98 def hello_in_a_string 100 99 @customers = [ Customer.new("david"), Customer.new("mary") ] 101 render _text "How's there? #{render_to_string("test/list")}"100 render :text => "How's there? " + render_to_string(:template => "test/list") 102 101 end 103 102 104 103 def accessing_params_in_template 105 render _template"Hello: <%= params[:name] %>"104 render :inline => "Hello: <%= params[:name] %>" 106 105 end 107 106 108 107 def accessing_local_assigns_in_inline_template … … 184 183 end 185 184 186 185 def test_do_with_render 187 assert_deprecated_render { get :render_hello_world }186 get :render_hello_world 188 187 assert_template "test/hello_world" 189 188 end 190 189 … … 229 228 def test_do_with_render_custom_code 230 229 get :render_custom_code 231 230 assert_response 404 231 assert_equal 'hello world', @response.body 232 232 end 233 233 234 def test_do_with_render_text_appendix235 get :render_text_appendix236 assert_response 404237 assert_equal 'hello world, goodbye!', @response.body238 end239 240 234 def test_do_with_render_nothing_with_appendix 241 235 get :render_nothing_with_appendix 242 236 assert_response 200 243 237 assert_equal 'appended', @response.body 244 238 end 245 239 240 def test_attempt_to_render_with_invalid_arguments 241 assert_raises(ActionController::RenderError) { get :render_invalid_args } 242 end 243 246 244 def test_attempt_to_access_object_method 247 245 assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone } 248 246 end … … 252 250 end 253 251 254 252 def test_render_xml 255 assert_deprecated_render { get :render_xml_hello }253 get :render_xml_hello 256 254 assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body 257 255 end 258 256 … … 415 413 end 416 414 417 415 protected 418 def assert_deprecated_render(&block) 419 assert_deprecated(/render/, &block) 420 end 421 416 422 417 def etag_for(text) 423 418 %("#{Digest::MD5.hexdigest(text)}") 424 419 end -
actionpack/test/controller/action_pack_assertions_test.rb
old new 7 7 def nothing() head :ok end 8 8 9 9 # a standard template 10 def hello_world() render "test/hello_world"; end10 def hello_world() render :template => "test/hello_world"; end 11 11 12 12 # a standard template 13 def hello_xml_world() render "test/hello_xml_world"; end13 def hello_xml_world() render :template => "test/hello_xml_world"; end 14 14 15 15 # a redirect to an internal location 16 16 def redirect_internal() redirect_to "/nothing"; end … … 38 38 # putting stuff in the flash 39 39 def flash_me 40 40 flash['hello'] = 'my name is inigo montoya...' 41 render _text"Inconceivable!"41 render :text => "Inconceivable!" 42 42 end 43 43 44 44 # we have a flash, but nothing is in it 45 45 def flash_me_naked 46 46 flash.clear 47 render _text"wow!"47 render :text => "wow!" 48 48 end 49 49 50 50 # assign some template instance variables … … 54 54 end 55 55 56 56 def render_based_on_parameters 57 render _text"Mr. #{params[:name]}"57 render :text => "Mr. #{params[:name]}" 58 58 end 59 59 60 60 def render_url 61 render _text"<div>#{url_for(:action => 'flash_me', :only_path => true)}</div>"61 render :text => "<div>#{url_for(:action => 'flash_me', :only_path => true)}</div>" 62 62 end 63 63 64 64 def render_text_with_custom_content_type … … 68 68 # puts something in the session 69 69 def session_stuffing 70 70 session['xmas'] = 'turkey' 71 render _text"ho ho ho"71 render :text => "ho ho ho" 72 72 end 73 73 74 74 # raises exception on get requests 75 75 def raise_on_get 76 76 raise "get" if request.get? 77 render _text"request method: #{request.env['REQUEST_METHOD']}"77 render :text => "request method: #{request.env['REQUEST_METHOD']}" 78 78 end 79 79 80 80 # raises exception on post requests 81 81 def raise_on_post 82 82 raise "post" if request.post? 83 render _text"request method: #{request.env['REQUEST_METHOD']}"83 render :text => "request method: #{request.env['REQUEST_METHOD']}" 84 84 end 85 85 86 86 def get_valid_record … … 310 310 process :nothing 311 311 assert !@response.rendered_with_file? 312 312 313 assert_deprecated(/render/) { process :hello_world }313 process :hello_world 314 314 assert @response.rendered_with_file? 315 315 assert 'hello_world', @response.rendered_file 316 316 end … … 461 461 end 462 462 463 463 def test_rendering_xml_sets_content_type 464 assert_deprecated(/render/) { process :hello_xml_world }464 process :hello_xml_world 465 465 assert_equal('application/xml; charset=utf-8', @response.headers['type']) 466 466 end 467 467 468 468 def test_rendering_xml_respects_content_type 469 469 @response.headers['type'] = 'application/pdf' 470 assert_deprecated(/render/) { process :hello_xml_world }470 process :hello_xml_world 471 471 assert_equal('application/pdf; charset=utf-8', @response.headers['type']) 472 472 end 473 473 -
actionpack/test/controller/new_render_test.rb
old new 152 152 def partial_with_hash_object 153 153 render :partial => "hash_object", :object => {:first_name => "Sam"} 154 154 end 155 155 156 def partial_hash_collection 157 render :partial => "hash_object", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ] 158 end 159 160 def partial_hash_collection_with_locals 161 render :partial => "hash_greeting", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ], :locals => { :greeting => "Hola" } 162 end 163 156 164 def partial_with_implicit_local_assignment 157 165 @customer = Customer.new("Marcel") 158 166 render :partial => "customer" … … 164 172 165 173 def hello_in_a_string 166 174 @customers = [ Customer.new("david"), Customer.new("mary") ] 167 render :text => "How's there? #{render_to_string("test/list")}"175 render :text => "How's there? " << render_to_string(:template => "test/list") 168 176 end 169 177 170 178 def render_to_string_with_assigns … … 203 211 end 204 212 205 213 def render_with_explicit_template 206 render "test/hello_world"214 render :template => "test/hello_world" 207 215 end 208 216 209 217 def double_render … … 614 622 end 615 623 616 624 def test_render_with_explicit_template 617 assert_deprecated(/render/) { get :render_with_explicit_template }625 get :render_with_explicit_template 618 626 assert_response :success 619 627 end 620 628 … … 675 683 get :partial_with_hash_object 676 684 assert_equal "Sam", @response.body 677 685 end 686 687 def test_hash_partial_collection 688 get :partial_hash_collection 689 assert_equal "PratikAmy", @response.body 690 end 691 692 def test_partial_hash_collection_with_locals 693 get :partial_hash_collection_with_locals 694 assert_equal "Hola: PratikHola: Amy", @response.body 695 end 678 696 679 697 def test_partial_with_implicit_local_assignment 680 698 get :partial_with_implicit_local_assignment -
actionpack/test/controller/session_management_test.rb
old new 5 5 session :off 6 6 7 7 def show 8 render _text"done"8 render :text => "done" 9 9 end 10 10 11 11 def tell 12 render _text"done"12 render :text => "done" 13 13 end 14 14 end 15 15 … … 20 20 :if => Proc.new { |r| r.parameters[:ws] } 21 21 22 22 def show 23 render _text"done"23 render :text => "done" 24 24 end 25 25 26 26 def tell 27 render _text"done"27 render :text => "done" 28 28 end 29 29 30 30 def conditional 31 render _text">>>#{params[:ws]}<<<"31 render :text => ">>>#{params[:ws]}<<<" 32 32 end 33 33 end 34 34 … … 36 36 session :disabled => false, :only => :something 37 37 38 38 def something 39 render _text"done"39 render :text => "done" 40 40 end 41 41 42 42 def another 43 render _text"done"43 render :text => "done" 44 44 end 45 45 end 46 46 -
actionpack/test/controller/components_test.rb
old new 14 14 end 15 15 16 16 def calling_from_template 17 render _template"Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>"17 render :inline => "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>" 18 18 end 19 19 20 20 def internal_caller 21 render _template"Are you there? <%= render_component(:action => 'internal_callee') %>"21 render :inline => "Are you there? <%= render_component(:action => 'internal_callee') %>" 22 22 end 23 23 24 24 def internal_callee 25 render _text"Yes, ma'am"25 render :text => "Yes, ma'am" 26 26 end 27 27 28 28 def set_flash … … 38 38 end 39 39 40 40 def calling_redirected_as_string 41 render _template"<%= render_component(:controller => 'callee', :action => 'redirected') %>"41 render :inline => "<%= render_component(:controller => 'callee', :action => 'redirected') %>" 42 42 end 43 43 44 44 def rescue_action(e) raise end … … 46 46 47 47 class CalleeController < ActionController::Base 48 48 def being_called 49 render _text"#{params[:name] || "Lady"} of the House, speaking"49 render :text => "#{params[:name] || "Lady"} of the House, speaking" 50 50 end 51 51 52 52 def blowing_up 53 render _text "It's game over, man, just game over, man!", "500 Internal Server Error"53 render :text => "It's game over, man, just game over, man!", :status => 500 54 54 end 55 55 56 56 def set_flash -
actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
old new 2 2 3 3 class DeprecatedBaseMethodsTest < Test::Unit::TestCase 4 4 class Target < ActionController::Base 5 def deprecated_render_parameters6 render "fun/games/hello_world"7 end8 5 9 6 def home_url(greeting) 10 7 "http://example.com/#{greeting}" … … 25 22 @controller = Target.new 26 23 end 27 24 28 def test_deprecated_render_parameters29 assert_deprecated("render('fun/games/hello_world')") do30 get :deprecated_render_parameters31 end32 33 assert_equal "Living in a nested world", @response.body34 end35 36 25 def test_log_error_silences_deprecation_warnings 37 26 get :raises_name_error 38 27 rescue => e -
actionpack/test/controller/filters_test.rb
old new 234 234 before_filter(AuditFilter) 235 235 236 236 def show 237 render _text"hello"237 render :text => "hello" 238 238 end 239 239 end 240 240 … … 271 271 before_filter :second, :only => :foo 272 272 273 273 def foo 274 render _text'foo'274 render :text => 'foo' 275 275 end 276 276 277 277 def bar 278 render _text'bar'278 render :text => 'bar' 279 279 end 280 280 281 281 protected -
actionpack/test/controller/cookie_test.rb
old new 33 33 34 34 def delete_cookie_with_path 35 35 cookies.delete("user_name", :path => '/beaten') 36 render _text"hello world"36 render :text => "hello world" 37 37 end 38 38 39 39 def rescue_action(e) -
actionpack/test/fixtures/test/_hash_greeting.erb
old new -
actionpack/lib/action_controller/components.rb
old new 78 78 # Renders the component specified as the response for the current method 79 79 def render_component(options) #:doc: 80 80 component_logging(options) do 81 render_ text(component_response(options, true).body, response.headers["Status"])81 render_for_text(component_response(options, true).body, response.headers["Status"]) 82 82 end 83 83 end 84 84 -
actionpack/lib/action_controller/benchmarking.rb
old new 43 43 protected 44 44 def render_with_benchmark(options = nil, deprecated_status = nil, &block) 45 45 unless logger 46 render_without_benchmark(options, deprecated_status,&block)46 render_without_benchmark(options, &block) 47 47 else 48 48 db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 49 49 50 50 render_output = nil 51 @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status,&block) }.real51 @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, &block) }.real 52 52 53 53 if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 54 54 @db_rt_before_render = db_runtime -
actionpack/lib/action_controller/caching.rb
old new 232 232 if cache = controller.read_fragment(cache_path.path) 233 233 controller.rendered_action_cache = true 234 234 set_content_type!(controller, cache_path) 235 controller.send(:render_ text, cache)235 controller.send(:render_for_text, cache) 236 236 false 237 237 else 238 238 controller.action_cache_path = cache_path -
actionpack/lib/action_controller/base.rb
old new 15 15 end 16 16 class MissingTemplate < ActionControllerError #:nodoc: 17 17 end 18 class RenderError < ActionControllerError #:nodoc: 19 end 18 20 class RoutingError < ActionControllerError #:nodoc: 19 21 attr_reader :failures 20 22 def initialize(message, failures=[]) … … 608 610 def view_paths 609 611 self.class.view_paths 610 612 end 611 612 protected 613 614 protected 613 615 # Renders the content that will be returned to the browser as the response body. 614 616 # 615 617 # === Rendering an action … … 628 630 # # but with a custom layout 629 631 # render :action => "long_goal", :layout => "spectacular" 630 632 # 631 # _Deprecation_ _notice_: This used to have the signatures <tt>render_action("action", status = 200)</tt>,632 # <tt>render_without_layout("controller/action", status = 200)</tt>, and633 # <tt>render_with_layout("controller/action", status = 200, layout)</tt>.634 #635 633 # === Rendering partials 636 634 # 637 635 # Partial rendering in a controller is most commonly used together with Ajax calls that only update one or a few elements on a page … … 698 696 # # Renders a template relative to the template root and chooses the proper file extension 699 697 # render :file => "some/template", :use_full_path => true 700 698 # 701 # _Deprecation_ _notice_: This used to have the signature <tt>render_file(path, status = 200)</tt>702 #703 699 # === Rendering text 704 700 # 705 701 # Rendering of text is usually used for tests or for rendering prepared content, such as a cache. By default, text … … 725 721 # # Renders "Hello from code!" 726 722 # render :text => proc { |response, output| output.write("Hello from code!") } 727 723 # 728 # _Deprecation_ _notice_: This used to have the signature <tt>render_text("text", status = 200)</tt>729 #730 724 # === Rendering JSON 731 725 # 732 726 # Rendering JSON sets the content type to text/x-json and optionally wraps the JSON in a callback. It is expected … … 756 750 # # Renders "hello david" 757 751 # render :inline => "<%= 'hello ' + name %>", :locals => { :name => "david" } 758 752 # 759 # _Deprecation_ _notice_: This used to have the signature <tt>render_template(template, status = 200, type = :rhtml)</tt>760 #761 753 # === Rendering inline JavaScriptGenerator page updates 762 754 # 763 755 # In addition to rendering JavaScriptGenerator page updates with Ajax in RJS templates (see ActionView::Base for details), … … 773 765 # All renders take the :status and :location options and turn them into headers. They can even be used together: 774 766 # 775 767 # render :xml => post.to_xml, :status => :created, :location => post_url(post) 776 def render(options = nil, deprecated_status = nil,&block) #:doc:768 def render(options = nil, &block) #:doc: 777 769 raise DoubleRenderError, "Can only render or redirect once per action" if performed? 778 770 779 771 if options.nil? 780 return render_f ile(default_template_name, deprecated_status, true)772 return render_for_file(default_template_name, nil, true) 781 773 else 782 # Backwards compatibility 783 unless options.is_a?(Hash) 784 if options == :update 785 options = { :update => true } 786 else 787 ActiveSupport::Deprecation.warn( 788 "You called render('#{options}'), which is a deprecated API call. Instead you use " + 789 "render :file => #{options}. Calling render with just a string will be removed from Rails 2.0.", 790 caller 791 ) 792 793 return render_file(options, deprecated_status, true) 794 end 774 if options == :update 775 options = { :update => true } 776 elsif !options.is_a?(Hash) 777 raise RenderError, "You called render with invalid options : #{options}" 795 778 end 796 779 end 797 780 … … 804 787 end 805 788 806 789 if text = options[:text] 807 render_ text(text, options[:status])790 render_for_text(text, options[:status]) 808 791 809 792 else 810 793 if file = options[:file] 811 render_f ile(file, options[:status], options[:use_full_path], options[:locals] || {})794 render_for_file(file, options[:status], options[:use_full_path], options[:locals] || {}) 812 795 813 796 elsif template = options[:template] 814 render_f ile(template, options[:status], true)797 render_for_file(template, options[:status], true) 815 798 816 799 elsif inline = options[:inline] 817 render_template(inline, options[:status], options[:type], options[:locals] || {}) 800 add_variables_to_assigns 801 render_for_text(@template.render_template(options[:type] || :erb, inline, nil, options[:locals] || {}), options[:status]) 818 802 819 803 elsif action_name = options[:action] 820 ActiveSupport::Deprecation.silence do 821 render_action(action_name, options[:status], options[:layout]) 822 end 804 template = default_template_name(action_name.to_s) 805 if options[:layout] && !template_exempt_from_layout?(template) 806 render_with_a_layout(:file => template, :status => options[:status], :use_full_path => true, :layout => true) 807 else 808 render_with_no_layout(:file => template, :status => options[:status], :use_full_path => true) 809 end 823 810 824 811 elsif xml = options[:xml] 825 render_xml(xml, options[:status]) 812 response.content_type = Mime::XML 813 render_for_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, options[:status]) 826 814 827 815 elsif json = options[:json] 828 render_json(json, options[:callback], options[:status]) 816 json = "#{options[:callback]}(#{json})" unless options[:callback].blank? 817 response.content_type = Mime::JSON 818 render_for_text(json, options[:status]) 829 819 830 820 elsif partial = options[:partial] 831 821 partial = default_template_name if partial == true 822 add_variables_to_assigns 832 823 if collection = options[:collection] 833 render_partial_collection(partial, collection, options[:spacer_template], options[:locals], options[:status]) 824 render_for_text(@template.send(:render_partial_collection, partial, collection, options[:spacer_template], options[:locals]), 825 options[:status]) 834 826 else 835 render_partial(partial, ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals], options[:status]) 827 render_for_text(@template.send(:render_partial, partial, ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals]), 828 options[:status]) 836 829 end 837 830 838 831 elsif options[:update] … … 840 833 @template.send :evaluate_assigns 841 834 842 835 generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block) 843 render_javascript(generator.to_s) 836 response.content_type = Mime::JS 837 render_for_text(generator.to_s) 844 838 845 839 elsif options[:nothing] 846 840 # Safari doesn't pass the headers of the return if the response is zero length 847 render_ text(" ", options[:status])841 render_for_text(" ", options[:status]) 848 842 849 843 else 850 render_file(default_template_name, options[:status], true) 851 844 render_for_file(default_template_name, options[:status], true) 852 845 end 853 846 end 854 847 end … … 856 849 # Renders according to the same rules as <tt>render</tt>, but returns the result in a string instead 857 850 # of sending it as the response body to the browser. 858 851 def render_to_string(options = nil, &block) #:doc: 859 ActiveSupport::Deprecation.silence { render(options, &block) }852 render(options, &block) 860 853 ensure 861 854 erase_render_results 862 855 forget_variables_added_to_assigns 863 856 reset_variables_added_to_assigns 864 857 end 865 858 866 def render_action(action_name, status = nil, with_layout = true) #:nodoc:867 template = default_template_name(action_name.to_s)868 if with_layout && !template_exempt_from_layout?(template)869 render_with_layout(:file => template, :status => status, :use_full_path => true, :layout => true)870 else871 render_without_layout(:file => template, :status => status, :use_full_path => true)872 end873 end874 875 def render_file(template_path, status = nil, use_full_path = false, locals = {}) #:nodoc:876 add_variables_to_assigns877 assert_existence_of_template_file(template_path) if use_full_path878 logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger879 render_text(@template.render_file(template_path, use_full_path, locals), status)880 end881 882 def render_template(template, status = nil, type = :erb, local_assigns = {}) #:nodoc:883 add_variables_to_assigns884 render_text(@template.render_template(type, template, nil, local_assigns), status)885 end886 887 def render_text(text = nil, status = nil, append_response = false) #:nodoc:888 @performed_render = true889 890 response.headers['Status'] = interpret_status(status || DEFAULT_RENDER_STATUS_CODE)891 892 if append_response893 response.body ||= ''894 response.body << text.to_s895 else896 response.body = text.is_a?(Proc) ? text : text.to_s897 end898 end899 900 def render_javascript(javascript, status = nil, append_response = true) #:nodoc:901 response.content_type = Mime::JS902 render_text(javascript, status, append_response)903 end904 905 def render_xml(xml, status = nil) #:nodoc:906 response.content_type = Mime::XML907 render_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, status)908 end909 910 def render_json(json, callback = nil, status = nil) #:nodoc:911 json = "#{callback}(#{json})" unless callback.blank?912 913 response.content_type = Mime::JSON914 render_text(json, status)915 end916 917 def render_nothing(status = nil) #:nodoc:918 render_text(' ', status)919 end920 921 def render_partial(partial_path = default_template_name, object = nil, local_assigns = nil, status = nil) #:nodoc:922 add_variables_to_assigns923 render_text(@template.send(:render_partial, partial_path, object, local_assigns), status)924 end925 926 def render_partial_collection(partial_name, collection, partial_spacer_template = nil, local_assigns = nil, status = nil) #:nodoc:927 add_variables_to_assigns928 render_text(@template.send(:render_partial_collection, partial_name, collection, partial_spacer_template, local_assigns), status)929 end930 931 def render_with_layout(template_name = default_template_name, status = nil, layout = nil) #:nodoc:932 render_with_a_layout(template_name, status, layout)933 end934 935 def render_without_layout(template_name = default_template_name, status = nil) #:nodoc:936 render_with_no_layout(template_name, status)937 end938 939 940 859 # Return a response that has no content (merely headers). The options 941 860 # argument is interpreted to be a hash of header names and values. 942 861 # This allows you to easily return a response that consists only of … … 1097 1016 end 1098 1017 1099 1018 private 1019 1020 def render_for_file(template_path, status = nil, use_full_path = false, locals = {}) #:nodoc: 1021 add_variables_to_assigns 1022 assert_existence_of_template_file(template_path) if use_full_path 1023 logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger 1024 render_for_text(@template.render_file(template_path, use_full_path, locals), status) 1025 end 1026 1027 def render_for_text(text = nil, status = nil, append_response = false) #:nodoc: 1028 @performed_render = true 1029 1030 response.headers['Status'] = interpret_status(status || DEFAULT_RENDER_STATUS_CODE) 1031 1032 if append_response 1033 response.body ||= '' 1034 response.body << text.to_s 1035 else 1036 response.body = text.is_a?(Proc) ? text : text.to_s 1037 end 1038 end 1039 1100 1040 def initialize_template_class(response) 1101 1041 raise "You must assign a template class through ActionController.template_class= before processing a request" unless @@template_class 1102 1042 -
actionpack/lib/action_controller/layout.rb
old new 233 233 end 234 234 235 235 protected 236 def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil,&block) #:nodoc:236 def render_with_a_layout(options = nil, &block) #:nodoc: 237 237 template_with_options = options.is_a?(Hash) 238 238 239 if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options , deprecated_layout))239 if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options)) 240 240 assert_existence_of_template_file(layout) 241 241 242 242 options = options.merge :layout => false if template_with_options 243 243 logger.info("Rendering template within #{layout}") if logger 244 244 245 if template_with_options 246 content_for_layout = render_with_no_layout(options, &block) 247 deprecated_status = options[:status] || deprecated_status 248 else 249 content_for_layout = render_with_no_layout(options, deprecated_status, &block) 250 end 251 245 content_for_layout = render_with_no_layout(options, &block) 252 246 erase_render_results 253 247 add_variables_to_assigns 254 248 @template.instance_variable_set("@content_for_layout", content_for_layout) 255 249 response.layout = layout 256 render_ text(@template.render_file(layout, true), deprecated_status)250 render_for_text(@template.render_file(layout, true)) 257 251 else 258 render_with_no_layout(options, deprecated_status,&block)252 render_with_no_layout(options, &block) 259 253 end 260 254 end 261 255 … … 272 266 !template_exempt_from_layout?(default_template_name(options[:action] || options[:template])) 273 267 end 274 268 275 def pick_layout(template_with_options, options, deprecated_layout) 276 if deprecated_layout 277 deprecated_layout 278 elsif template_with_options 269 def pick_layout(template_with_options, options) 270 if template_with_options 279 271 case layout = options[:layout] 280 272 when FalseClass 281 273 nil -
actionpack/lib/action_controller/rescue.rb
old new 125 125 @template.instance_variable_set("@contents", @template.render_file(template_path_for_local_rescue(exception), false)) 126 126 127 127 response.content_type = Mime::HTML 128 render_f ile(rescues_path("layout"), response_code_for_rescue(exception))128 render_for_file(rescues_path("layout"), response_code_for_rescue(exception)) 129 129 end 130 130 131 131 private -
actionpack/lib/action_view/partials.rb
old new 46 46 # This will render the partial "advertisement/_ad.erb" regardless of which controller this is being called from. 47 47 module Partials 48 48 private 49 # Deprecated, use render :partial 50 def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc: 49 def render_partial(partial_path, object_assigns = nil, local_assigns = nil) #:nodoc: 51 50 case partial_path 52 51 when String, Symbol, NilClass 53 52 path, partial_name = partial_pieces(partial_path) 54 object = extracting_object(partial_name, local_assigns, deprecated_local_assigns) 55 local_assigns = extract_local_assigns(local_assigns, deprecated_local_assigns) 53 object = extracting_object(partial_name, object_assigns) 56 54 local_assigns = local_assigns ? local_assigns.clone : {} 57 55 add_counter_to_local_assigns!(partial_name, local_assigns) 58 56 add_object_to_local_assigns!(partial_name, local_assigns, object) … … 68 66 if partial_path.any? 69 67 path = ActionController::RecordIdentifier.partial_path(partial_path.first) 70 68 collection = partial_path 71 render_partial_collection(path, collection, nil, local_assigns.value)69 render_partial_collection(path, collection, nil, object_assigns.value) 72 70 else 73 71 "" 74 72 end 75 73 else 76 74 render_partial( 77 75 ActionController::RecordIdentifier.partial_path(partial_path), 78 local_assigns, deprecated_local_assigns)76 object_assigns, local_assigns) 79 77 end 80 78 end 81 79 82 # Deprecated, use render :partial, :collection83 80 def render_partial_collection(partial_name, collection, partial_spacer_template = nil, local_assigns = nil) #:nodoc: 84 81 collection_of_partials = Array.new 85 82 counter_name = partial_counter_name(partial_name) … … 117 114 partial_name.split('/').last.split('.').first.intern 118 115 end 119 116 120 def extracting_object(partial_name, local_assigns, deprecated_local_assigns)117 def extracting_object(partial_name, object_assigns) 121 118 variable_name = partial_variable_name(partial_name) 122 if local_assigns.is_a?(Hash) || local_assigns.nil?119 if object_assigns.nil? 123 120 controller.instance_variable_get("@#{variable_name}") 124 121 else 125 # deprecated form where object could be passed in as second parameter 126 local_assigns 122 object_assigns 127 123 end 128 124 end 129 125 130 def extract_local_assigns(local_assigns, deprecated_local_assigns)131 local_assigns.is_a?(Hash) ? local_assigns : deprecated_local_assigns132 end133 134 126 def add_counter_to_local_assigns!(partial_name, local_assigns) 135 127 counter_name = partial_counter_name(partial_name) 136 128 local_assigns[counter_name] = 1 unless local_assigns.has_key?(counter_name) -
actionpack/examples/benchmark.rb
old new 7 7 8 8 class BenchmarkController < ActionController::Base 9 9 def message 10 render _text"hello world"10 render :text => "hello world" 11 11 end 12 12 13 13 def list