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

Changeset 4699

Show
Ignore:
Timestamp:
08/07/06 06:11:56 (2 years ago)
Author:
bitsweat
Message:

Deprecation! @session and @flash will be removed after 1.2. Use the session and flash methods instead. You'll get printed warnings during tests and logged warnings in dev mode when you access either instance variable directly.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r4678 r4699  
    11*SVN* 
     2 
     3* Deprecation! @session and @flash will be removed after 1.2. Use the session and flash methods instead. You'll get printed warnings during tests and logged warnings in dev mode when you access either instance variable directly. [Jeremy Kemper] 
    24 
    35* Make Routing noisy when an anchor regexp is assigned to a segment. #5674 [francois.beausoleil@gmail.com] 
  • trunk/actionpack/examples/blog_controller.cgi

    r4 r4699  
    1515    render_template <<-"EOF" 
    1616      <html><body> 
    17       <%= @flash["alert"] %> 
     17      <%= flash["alert"] %> 
    1818      <h1>Posts</h1> 
    1919      <% @posts.each do |post| %> 
  • trunk/actionpack/lib/action_controller/base.rb

    r4664 r4699  
    4343  end 
    4444  class RedirectBackError < ActionControllerError #:nodoc: 
    45     DEFAULT_MESSAGE = 'No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify @request.env["HTTP_REFERER"].' 
    46    
     45    DEFAULT_MESSAGE = 'No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify request.env["HTTP_REFERER"].' 
     46 
    4747    def initialize(message = nil) 
    4848      super(message || DEFAULT_MESSAGE) 
     
    6060  #       @entries = Entry.find(:all) 
    6161  #     end 
    62   #      
     62  # 
    6363  #     def sign 
    6464  #       Entry.create(params[:entry]) 
     
    301301    # Holds a hash of objects in the session. Accessed like <tt>session[:person]</tt> to get the object tied to the "person" 
    302302    # key. The session will hold any type of object as values, but the key should be a string or symbol. 
    303     attr_accessor :session 
    304      
     303    attr_internal :session 
     304 
    305305    # Holds a hash of header names and values. Accessed like <tt>headers["Cache-Control"]</tt> to get the value of the Cache-Control 
    306306    # directive. Values should always be specified as strings. 
     
    401401        initialize_template_class(response) 
    402402        assign_shortcuts(request, response) 
     403        assign_deprecated_shortcuts(request, response) 
    403404        initialize_current_url 
    404405        assign_names 
     
    753754      def render_text(text = nil, status = nil) #:nodoc: 
    754755        @performed_render = true 
    755         @response.headers['Status'] = (status || DEFAULT_RENDER_STATUS_CODE).to_s 
    756         @response.body = text 
     756        response.headers['Status'] = (status || DEFAULT_RENDER_STATUS_CODE).to_s 
     757        response.body = text 
    757758      end 
    758759 
    759760      def render_javascript(javascript, status = nil) #:nodoc: 
    760         @response.headers['Content-Type'] = 'text/javascript; charset=UTF-8' 
     761        response.headers['Content-Type'] = 'text/javascript; charset=UTF-8' 
    761762        render_text(javascript, status) 
    762763      end 
    763764 
    764765      def render_xml(xml, status = nil) #:nodoc: 
    765         @response.headers['Content-Type'] = 'application/xml' 
     766        response.headers['Content-Type'] = 'application/xml' 
    766767        render_text(xml, status) 
    767768      end 
     
    792793      # Clears the rendered results, allowing for another render to be performed. 
    793794      def erase_render_results #:nodoc: 
    794         @response.body = nil 
     795        response.body = nil 
    795796        @performed_render = false 
    796797      end 
     
    894895        cache_options.delete_if { |k,v| v.nil? or v == false } 
    895896        cache_control = cache_options.map{ |k,v| v == true ? k.to_s : "#{k.to_s}=#{v.to_s}"} 
    896         @response.headers["Cache-Control"] = cache_control.join(', ') 
     897        response.headers["Cache-Control"] = cache_control.join(', ') 
    897898      end 
    898899       
     
    900901      # intermediate caches (like caching proxy servers). 
    901902      def expires_now #:doc: 
    902         @response.headers["Cache-Control"] = "no-cache" 
     903        response.headers["Cache-Control"] = "no-cache" 
    903904      end 
    904905 
    905906      # Resets the session by clearing out all the objects stored within and initializing a new session object. 
    906907      def reset_session #:doc: 
    907         @request.reset_session 
    908         @session = @request.session 
    909         @response.session = @session 
     908        request.reset_session 
     909        @_session = request.session 
     910        response.session = @_session 
    910911      end 
    911912     
     
    930931        @performed_render = @performed_redirect = false 
    931932      end 
    932      
     933 
    933934      def assign_shortcuts(request, response) 
    934935        @request, @params, @cookies = request, request.parameters, request.cookies 
     
    937938        @response.session = request.session 
    938939 
    939         @session  = @response.session 
     940        @_session  = @response.session 
    940941        @template = @response.template 
    941942        @assigns  = @response.template.assigns 
    942    
     943 
    943944        @headers  = @response.headers 
    944945      end 
    945        
     946 
     947 
     948      # TODO: assigns cookies headers params request response template 
     949      DEPRECATED_INSTANCE_VARIABLES = %w(flash session) 
     950 
     951      # Gone after 1.2. 
     952      def assign_deprecated_shortcuts(request, response) 
     953        DEPRECATED_INSTANCE_VARIABLES.each do |var| 
     954          instance_variable_set "@#{var}", ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, var) 
     955        end 
     956      end 
     957 
    946958      def initialize_current_url 
    947         @url = UrlRewriter.new(@request, @params.clone()
     959        @url = UrlRewriter.new(request, params.clone
    948960      end 
    949961 
     
    951963        if logger 
    952964          logger.info "\n\nProcessing #{controller_class_name}\##{action_name} (for #{request_origin}) [#{request.method.to_s.upcase}]" 
    953           logger.info "  Session ID: #{@session.session_id}" if @session and @session.respond_to?(:session_id) 
    954           logger.info "  Parameters: #{respond_to?(:filter_parameters) ? filter_parameters(@params).inspect : @params.inspect}" 
     965          logger.info "  Session ID: #{@_session.session_id}" if @_session and @_session.respond_to?(:session_id) 
     966          logger.info "  Parameters: #{respond_to?(:filter_parameters) ? filter_parameters(params).inspect : params.inspect}" 
    955967        end 
    956968      end 
     
    10241036        # this *needs* to be cached! 
    10251037        # otherwise you'd get different results if calling it more than once 
    1026         @request_origin ||= "#{@request.remote_ip} at #{Time.now.to_s(:db)}" 
    1027       end 
    1028        
     1038        @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}" 
     1039      end 
     1040 
    10291041      def complete_request_uri 
    1030         "#{@request.protocol}#{@request.host}#{@request.request_uri}" 
     1042        "#{request.protocol}#{request.host}#{request.request_uri}" 
    10311043      end 
    10321044 
    10331045      def close_session 
    1034         @session.close unless @session.nil? || Hash === @session 
    1035       end 
    1036        
     1046        @_session.close if @_session && @_session.respond_to?(:close) 
     1047      end 
     1048 
    10371049      def template_exists?(template_name = default_template_name) 
    10381050        @template.file_exists?(template_name) 
  • trunk/actionpack/lib/action_controller/components.rb

    r4595 r4699  
    112112 
    113113        def flash_with_components(refresh = false) #:nodoc: 
    114           if !defined?(@flash) || refresh 
    115             @flash = 
     114          if !defined?(@_flash) || refresh 
     115            @_flash = 
    116116              if defined?(@parent_controller) 
    117117                @parent_controller.flash 
     
    120120              end 
    121121          end 
    122            
    123           @flash 
     122          @_flash 
    124123        end 
    125124 
  • trunk/actionpack/lib/action_controller/flash.rb

    r4617 r4699  
    1818  # 
    1919  #   display.rhtml 
    20   #     <% if @flash[:notice] %><div class="notice"><%= @flash[:notice] %></div><% end %> 
     20  #     <% if flash[:notice] %><div class="notice"><%= flash[:notice] %></div><% end %> 
    2121  # 
    2222  # This example just places a string in the flash, but you can put any object in there. And of course, you can put as many 
     
    142142       
    143143      def process_cleanup_with_flash 
    144         flash.sweep if @session 
     144        flash.sweep if @_session 
    145145        process_cleanup_without_flash 
    146146      end 
     
    148148      def reset_session_with_flash 
    149149        reset_session_without_flash 
    150         remove_instance_variable(:@flash) 
     150        remove_instance_variable(:@_flash) 
    151151        flash(:refresh) 
    152152      end 
     
    157157        # Note that if sessions are disabled only flash.now will work. 
    158158        def flash(refresh = false) #:doc: 
    159           if !defined?(@flash) || refresh 
    160             @flash = 
    161               if @session.is_a?(Hash) 
    162                 # @session is a Hash, if sessions are disabled 
    163                 # we don't put the flash in the session in this case 
     159          if !defined?(@_flash) || refresh 
     160            @_flash = 
     161              if session.is_a?(Hash) 
     162                # don't put flash in session if disabled 
    164163                FlashHash.new 
    165164              else 
    166                 # otherwise, @session is a CGI::Session or a TestSession 
     165                # otherwise, session is a CGI::Session or a TestSession 
    167166                # so make sure it gets retrieved from/saved to session storage after request processing 
    168                 @session["flash"] ||= FlashHash.new 
     167                session["flash"] ||= FlashHash.new 
    169168              end 
    170169          end 
    171            
    172           @flash 
     170 
     171          @_flash 
    173172        end 
    174173 
  • trunk/actionpack/lib/action_controller/session_management.rb

    r4312 r4699  
    129129      # is not a standard way to iterate over session data. 
    130130      def clear_persistent_model_associations #:doc: 
    131         if defined?(@session) && @session.instance_variables.include?('@data') 
    132           session_data = @session.instance_variable_get('@data') 
     131        if defined?(@_session) && @_session.instance_variables.include?('@data') 
     132          session_data = @_session.instance_variable_get('@data') 
    133133 
    134134          if session_data && session_data.respond_to?(:each_value)