Changeset 3441
- Timestamp:
- 01/20/06 22:04:07 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (8 diffs)
- trunk/actionpack/lib/action_controller/benchmarking.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/layout.rb (modified) (3 diffs)
- trunk/actionpack/test/controller/new_render_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r3438 r3441 1 1 *SVN* 2 3 * Add render :update for inline RJS. [Sam Stephenson] Example: 4 class UserController < ApplicationController 5 def refresh 6 render :update do |page| 7 page.replace_html 'user_list', :partial => 'user', :collection => @users 8 page.visual_effect :highlight, 'user_list' 9 end 10 end 11 end 2 12 3 13 * allow nil objects for error_messages_for [Michael Koziarski] trunk/actionpack/lib/action_controller/base.rb
r3406 r3441 369 369 # Returns a URL that has been rewritten according to the options hash and the defined Routes. 370 370 # (For doing a complete redirect, use redirect_to). 371 # 371 # Â 372 372 # <tt>url_for</tt> is used to: 373 # 373 # Â 374 374 # All keys given to url_for are forwarded to the Route module, save for the following: 375 375 # * <tt>:anchor</tt> -- specifies the anchor name to be appended to the path. For example, … … 387 387 # The default Routes setup supports a typical Rails path of "controller/action/id" where action and id are optional, with 388 388 # action defaulting to 'index' when not given. Here are some typical url_for statements and their corresponding URLs: 389 # 389 # Â 390 390 # url_for :controller => 'posts', :action => 'recent' # => 'proto://host.com/posts/recent' 391 391 # url_for :controller => 'posts', :action => 'index' # => 'proto://host.com/posts' … … 396 396 # other parameters, including <tt>:controller</tt>, <tt>:id</tt>, and any other parameters that are placed into a Route's 397 397 # path. 398 # 398 # Â 399 399 # The URL helpers such as <tt>url_for</tt> have a limited form of memory: when generating a new URL, they can look for 400 400 # missing values in the current request's parameters. Routes attempts to guess when a value should and should not be … … 419 419 # value that appears in the slot for <tt>:first</tt> is not equal to default value for <tt>:first</tt> we stop using 420 420 # defaults. On it's own, this rule can account for much of the typical Rails URL behavior. 421 # 421 # Â 422 422 # Although a convienence, defaults can occasionaly get in your way. In some cases a default persists longer than desired. 423 423 # The default may be cleared by adding <tt>:name => nil</tt> to <tt>url_for</tt>'s options. … … 572 572 # _Deprecation_ _notice_: This used to have the signature <tt>render_template(template, status = 200, type = :rhtml)</tt> 573 573 # 574 # === Rendering inline JavaScriptGenerator page updates 575 # 576 # In addition to rendering JavaScriptGenerator page updates with Ajax in RJS templates (see ActionView::Base for details), 577 # you can also pass the <tt>:update</tt> parameter to +render+, along with a block, to render page updates inline. 578 # 579 # render :update do |page| 580 # page.replace_html 'user_list', :partial => 'user', :collection => @users 581 # page.visual_effect :highlight, 'user_list' 582 # end 583 # 574 584 # === Rendering nothing 575 585 # … … 582 592 # # Renders an empty response with status code 401 (access denied) 583 593 # render :nothing => true, :status => 401 584 def render(options = nil, deprecated_status = nil ) #:doc:594 def render(options = nil, deprecated_status = nil, &block) #:doc: 585 595 raise DoubleRenderError, "Can only render or redirect once per action" if performed? 586 596 587 597 # Backwards compatibility 588 598 unless options.is_a?(Hash) 589 return render_file(options || default_template_name, deprecated_status, true) 599 if options == :update 600 options = {:update => true} 601 else 602 return render_file(options || default_template_name, deprecated_status, true) 603 end 590 604 end 591 605 … … 614 628 end 615 629 630 elsif options[:update] 631 generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block) 632 render_javascript(generator.to_s) 633 616 634 elsif options[:nothing] 617 635 # Safari doesn't pass the headers of the return if the response is zero length … … 660 678 @response.headers['Status'] = (status || DEFAULT_RENDER_STATUS_CODE).to_s 661 679 @response.body = text 680 end 681 682 def render_javascript(javascript, status = nil) 683 @response.headers['Content-type'] = 'text/javascript' 684 render_text(javascript, status) 662 685 end 663 686 trunk/actionpack/lib/action_controller/benchmarking.rb
r2401 r3441 44 44 end 45 45 46 def render_with_benchmark(options = nil, deprecated_status = nil )46 def render_with_benchmark(options = nil, deprecated_status = nil, &block) 47 47 unless logger 48 render_without_benchmark(options, deprecated_status )48 render_without_benchmark(options, deprecated_status, &block) 49 49 else 50 50 db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? 51 51 52 52 render_output = nil 53 @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status ) }.real53 @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status, &block) }.real 54 54 55 55 if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? trunk/actionpack/lib/action_controller/layout.rb
r3423 r3441 212 212 end 213 213 214 def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil ) #:nodoc:214 def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) #:nodoc: 215 215 template_with_options = options.is_a?(Hash) 216 216 … … 220 220 221 221 if template_with_options 222 content_for_layout = render_with_no_layout(options )222 content_for_layout = render_with_no_layout(options, &block) 223 223 deprecated_status = options[:status] || deprecated_status 224 224 else 225 content_for_layout = render_with_no_layout(options, deprecated_status )225 content_for_layout = render_with_no_layout(options, deprecated_status, &block) 226 226 end 227 227 … … 231 231 render_text(@template.render_file(layout, true), deprecated_status) 232 232 else 233 render_with_no_layout(options, deprecated_status )233 render_with_no_layout(options, deprecated_status, &block) 234 234 end 235 235 end trunk/actionpack/test/controller/new_render_test.rb
r3321 r3441 187 187 @project_id = 4 188 188 render :action => 'delete_with_js' 189 end 190 191 def update_page 192 render :update do |page| 193 page.replace_html 'balance', '$37,000,000.00' 194 page.visual_effect :highlight, 'balance' 195 end 189 196 end 190 197 … … 481 488 end 482 489 490 def test_update_page 491 get :update_page 492 assert_equal 'text/javascript', @response.headers['Content-type'] 493 assert_equal 2, @response.body.split($/).length 494 end 495 483 496 def test_yield_content_for 484 497 get :yield_content_for