Changeset 4699
- Timestamp:
- 08/07/06 06:11:56 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/examples/blog_controller.cgi (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (12 diffs)
- trunk/actionpack/lib/action_controller/components.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/flash.rb (modified) (4 diffs)
- trunk/actionpack/lib/action_controller/session_management.rb (modified) (1 diff)
- trunk/actionpack/test/controller/deprecated_instance_variables_test.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r4678 r4699 1 1 *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] 2 4 3 5 * 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 15 15 render_template <<-"EOF" 16 16 <html><body> 17 <%= @flash["alert"] %>17 <%= flash["alert"] %> 18 18 <h1>Posts</h1> 19 19 <% @posts.each do |post| %> trunk/actionpack/lib/action_controller/base.rb
r4664 r4699 43 43 end 44 44 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 47 47 def initialize(message = nil) 48 48 super(message || DEFAULT_MESSAGE) … … 60 60 # @entries = Entry.find(:all) 61 61 # end 62 # 62 # 63 63 # def sign 64 64 # Entry.create(params[:entry]) … … 301 301 # Holds a hash of objects in the session. Accessed like <tt>session[:person]</tt> to get the object tied to the "person" 302 302 # key. The session will hold any type of object as values, but the key should be a string or symbol. 303 attr_ accessor:session304 303 attr_internal :session 304 305 305 # Holds a hash of header names and values. Accessed like <tt>headers["Cache-Control"]</tt> to get the value of the Cache-Control 306 306 # directive. Values should always be specified as strings. … … 401 401 initialize_template_class(response) 402 402 assign_shortcuts(request, response) 403 assign_deprecated_shortcuts(request, response) 403 404 initialize_current_url 404 405 assign_names … … 753 754 def render_text(text = nil, status = nil) #:nodoc: 754 755 @performed_render = true 755 @response.headers['Status'] = (status || DEFAULT_RENDER_STATUS_CODE).to_s756 @response.body = text756 response.headers['Status'] = (status || DEFAULT_RENDER_STATUS_CODE).to_s 757 response.body = text 757 758 end 758 759 759 760 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' 761 762 render_text(javascript, status) 762 763 end 763 764 764 765 def render_xml(xml, status = nil) #:nodoc: 765 @response.headers['Content-Type'] = 'application/xml'766 response.headers['Content-Type'] = 'application/xml' 766 767 render_text(xml, status) 767 768 end … … 792 793 # Clears the rendered results, allowing for another render to be performed. 793 794 def erase_render_results #:nodoc: 794 @response.body = nil795 response.body = nil 795 796 @performed_render = false 796 797 end … … 894 895 cache_options.delete_if { |k,v| v.nil? or v == false } 895 896 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(', ') 897 898 end 898 899 … … 900 901 # intermediate caches (like caching proxy servers). 901 902 def expires_now #:doc: 902 @response.headers["Cache-Control"] = "no-cache"903 response.headers["Cache-Control"] = "no-cache" 903 904 end 904 905 905 906 # Resets the session by clearing out all the objects stored within and initializing a new session object. 906 907 def reset_session #:doc: 907 @request.reset_session908 @ session = @request.session909 @response.session = @session908 request.reset_session 909 @_session = request.session 910 response.session = @_session 910 911 end 911 912 … … 930 931 @performed_render = @performed_redirect = false 931 932 end 932 933 933 934 def assign_shortcuts(request, response) 934 935 @request, @params, @cookies = request, request.parameters, request.cookies … … 937 938 @response.session = request.session 938 939 939 @ session = @response.session940 @_session = @response.session 940 941 @template = @response.template 941 942 @assigns = @response.template.assigns 942 943 943 944 @headers = @response.headers 944 945 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 946 958 def initialize_current_url 947 @url = UrlRewriter.new( @request, @params.clone())959 @url = UrlRewriter.new(request, params.clone) 948 960 end 949 961 … … 951 963 if logger 952 964 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}" 955 967 end 956 968 end … … 1024 1036 # this *needs* to be cached! 1025 1037 # 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 1029 1041 def complete_request_uri 1030 "#{ @request.protocol}#{@request.host}#{@request.request_uri}"1042 "#{request.protocol}#{request.host}#{request.request_uri}" 1031 1043 end 1032 1044 1033 1045 def close_session 1034 @ session.close unless @session.nil? || Hash === @session1035 end 1036 1046 @_session.close if @_session && @_session.respond_to?(:close) 1047 end 1048 1037 1049 def template_exists?(template_name = default_template_name) 1038 1050 @template.file_exists?(template_name) trunk/actionpack/lib/action_controller/components.rb
r4595 r4699 112 112 113 113 def flash_with_components(refresh = false) #:nodoc: 114 if !defined?(@ flash) || refresh115 @ flash =114 if !defined?(@_flash) || refresh 115 @_flash = 116 116 if defined?(@parent_controller) 117 117 @parent_controller.flash … … 120 120 end 121 121 end 122 123 @flash 122 @_flash 124 123 end 125 124 trunk/actionpack/lib/action_controller/flash.rb
r4617 r4699 18 18 # 19 19 # display.rhtml 20 # <% if @flash[:notice] %><div class="notice"><%= @flash[:notice] %></div><% end %>20 # <% if flash[:notice] %><div class="notice"><%= flash[:notice] %></div><% end %> 21 21 # 22 22 # 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 … … 142 142 143 143 def process_cleanup_with_flash 144 flash.sweep if @ session144 flash.sweep if @_session 145 145 process_cleanup_without_flash 146 146 end … … 148 148 def reset_session_with_flash 149 149 reset_session_without_flash 150 remove_instance_variable(:@ flash)150 remove_instance_variable(:@_flash) 151 151 flash(:refresh) 152 152 end … … 157 157 # Note that if sessions are disabled only flash.now will work. 158 158 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 164 163 FlashHash.new 165 164 else 166 # otherwise, @session is a CGI::Session or a TestSession165 # otherwise, session is a CGI::Session or a TestSession 167 166 # so make sure it gets retrieved from/saved to session storage after request processing 168 @session["flash"] ||= FlashHash.new167 session["flash"] ||= FlashHash.new 169 168 end 170 169 end 171 172 @ flash170 171 @_flash 173 172 end 174 173 trunk/actionpack/lib/action_controller/session_management.rb
r4312 r4699 129 129 # is not a standard way to iterate over session data. 130 130 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') 133 133 134 134 if session_data && session_data.respond_to?(:each_value)