Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3581

Show
Ignore:
Timestamp:
02/12/06 06:11:17 (3 years ago)
Author:
david
Message:

Flash shouldnt depend on components either [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/components.rb

    r3580 r3581  
    5252        alias_method :set_session_options_without_components, :set_session_options 
    5353        alias_method :set_session_options, :set_session_options_with_components 
     54         
     55        alias_method :flash_without_components, :flash 
     56        alias_method :flash, :flash_with_components 
    5457      end 
    5558       
     
    109112            end 
    110113          end 
     114        end 
     115 
     116        def flash_with_components(refresh = false) 
     117          if @flash.nil? || refresh 
     118            @flash =  
     119              if @parent_controller 
     120                @parent_controller.flash 
     121              else 
     122                flash_without_components 
     123              end 
     124          end 
     125           
     126          @flash 
    111127        end 
    112128 
  • trunk/actionpack/lib/action_controller/flash.rb

    r3580 r3581  
    2929 
    3030      base.class_eval do 
     31        alias_method :assign_shortcuts_without_flash, :assign_shortcuts 
     32        alias_method :assign_shortcuts, :assign_shortcuts_with_flash 
     33 
    3134        alias_method :process_cleanup_without_flash, :process_cleanup 
    3235        alias_method :process_cleanup, :process_cleanup_with_flash 
     
    3639     
    3740    class FlashNow #:nodoc: 
    38       def initialize flash 
     41      def initialize(flash) 
    3942        @flash = flash 
    4043      end 
     
    135138 
    136139    module InstanceMethods 
     140      def assign_shortcuts_with_flash(request, response) #:nodoc: 
     141        assign_shortcuts_without_flash(request, response) 
     142        flash(:refresh) 
     143      end 
     144       
    137145      def process_cleanup_with_flash 
    138146        process_cleanup_without_flash 
     
    144152        # <tt>flash["notice"] = "hello"</tt> to put a new one. 
    145153        # Note that if sessions are disabled only flash.now will work. 
    146         def flash #:doc: 
    147           @flash ||=  
    148             if @parent_controller 
    149               @parent_controller.flash 
    150             elsif @session.is_a?(Hash) 
    151               # @session is a Hash, if sessions are disabled 
    152               # we don't put the flash in the session in this case 
    153               FlashHash.new 
    154             else 
    155               # otherwise, @session is a CGI::Session or a TestSession 
    156               # so make sure it gets retrieved from/saved to session storage after request processing 
    157               @session["flash"] ||= FlashHash.new 
    158             end 
     154        def flash(refresh = false) #:doc: 
     155          if @flash.nil? || refresh 
     156            @flash =  
     157              if @session.is_a?(Hash) 
     158                # @session is a Hash, if sessions are disabled 
     159                # we don't put the flash in the session in this case 
     160                FlashHash.new 
     161              else 
     162                # otherwise, @session is a CGI::Session or a TestSession 
     163                # so make sure it gets retrieved from/saved to session storage after request processing 
     164                @session["flash"] ||= FlashHash.new 
     165              end 
     166          end 
     167           
     168          @flash 
    159169        end 
    160170