Changeset 462
- Timestamp:
- 01/20/05 14:13:34 (4 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (5 diffs)
- trunk/actionpack/lib/action_controller/filters.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/filters_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r458 r462 1 *SVN* 2 3 * Fixed that a default fragment store wan't being set to MemoryStore as intended. 4 5 * Fixed that all redirect and render calls now return true, so you can use the pattern of "do and return". Example: 6 7 def show 8 redirect_to(:action => "login") and return unless @person.authenticated? 9 render_text "I won't happen unless the person is authenticated" 10 end 11 12 * Added that renders and redirects called in before_filters will have the same effect as returning false: stopping the chain. Example: 13 14 class WeblogController 15 before_filter { |c| c.send(:redirect_to_url("http://www.farfaraway.com")}) } 16 17 def hello 18 render_text "I will never be called" 19 end 20 end 21 22 23 * Added that only one render or redirect can happen per action. The first call wins and subsequent calls are ignored. Example: 24 25 def do_something 26 redirect_to :action => "elsewhere" 27 render_action "overthere" 28 end 29 30 Only the redirect happens. The rendering call is simply ignored. 31 32 1 33 *1.3.1* (January 18th, 2005) 2 34 trunk/actionpack/lib/action_controller/base.rb
r427 r462 163 163 # For more examples of redirecting options, have a look at the unit test in test/controller/url_test.rb. It's very readable and will give 164 164 # you an excellent understanding of the different options and what they do. 165 # 166 # == Calling multiple redirects or renders 167 # 168 # The rule for handling calls of multiple redirects and renders is that the first call wins. So in the following example: 169 # 170 # def do_something 171 # redirect_to :action => "elsewhere" 172 # render_action "overthere" 173 # end 174 # 175 # Only the redirect happens. The rendering call is simply ignored. 165 176 # 166 177 # == Environments … … 386 397 # Use block for response body if provided (useful for deferred rendering or streaming output). 387 398 def render_text(text = nil, status = nil, &block) #:doc: 399 return if performed? 388 400 add_variables_to_assigns 389 401 @response.headers["Status"] = status || DEFAULT_RENDER_STATUS_CODE 390 402 @response.body = block_given? ? block : text 391 403 @performed_render = true 392 return false393 404 end 394 405 … … 542 553 # second parameter and the browser will get "301 Moved Permanently" instead of "302 Found". 543 554 def redirect_to_url(url, permanently = false) #:doc: 555 return if performed? 544 556 logger.info("Redirected to #{url}") unless logger.nil? 545 557 @response.redirect(url, permanently) 546 558 @performed_redirect = true 547 return false548 559 end 549 560 … … 595 606 if action_methods.include?(action_name) || action_methods.include?('method_missing') 596 607 send(action_name) 597 render unless @performed_render || @performed_redirect608 render unless performed? 598 609 elsif template_exists? && template_public? 599 610 render … … 601 612 raise UnknownAction, "No action responded to #{action_name}", caller 602 613 end 614 end 615 616 def performed? 617 @performed_render || @performed_redirect 603 618 end 604 619 trunk/actionpack/lib/action_controller/filters.rb
r354 r462 13 13 # Filters have access to the request, response, and all the instance variables set by other filters in the chain 14 14 # or by the action (in the case of after filters). Additionally, it's possible for a pre-processing <tt>before_filter</tt> 15 # to halt the processing before the intended action is processed by returning false . This is especially useful for16 # filters like authentication where you're not interested in allowing the action to be performed if the proper17 # credentials are not in order.15 # to halt the processing before the intended action is processed by returning false or performing a redirect or render. 16 # This is especially useful for filters like authentication where you're not interested in allowing the action to be 17 # performed if the proper credentials are not in order. 18 18 # 19 19 # == Filter inheritance … … 291 291 292 292 def perform_action_with_filters 293 return if before_action == false 293 return if before_action == false || performed? 294 294 perform_action_without_filters 295 295 after_action trunk/actionpack/test/controller/filters_test.rb
r354 r462 13 13 @ran_filter ||= [] 14 14 @ran_filter << "ensure_login" 15 end 16 end 17 18 class RenderingController < ActionController::Base 19 before_filter :render_something_else 20 21 def show 22 @ran_action = true 23 render_text "ran action" 24 end 25 26 private 27 def render_something_else 28 render_text "something else" 15 29 end 16 30 end … … 265 279 MixedFilterController.execution_log 266 280 end 281 282 def test_rendering_breaks_filtering_chain 283 response = test_process(RenderingController) 284 assert_equal "something else", response.body 285 assert !response.template.assigns["ran_action"] 286 end 267 287 268 288 private