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

Ticket #2291: component_flash_fix_2.2322.diff

File component_flash_fix_2.2322.diff, 3.4 kB (added by divoxx, 3 years ago)

Totally different approach. Adds a component_call? method that could potentially be used in other cases like this

  • actionpack/test/controller/request_test.rb

    old new  
    5252    assert_nil @request.domain 
    5353  end 
    5454 
     55  def test_component_call 
     56    assert !@request.component_call? 
     57 
     58    @request.env['HTTP_X_REQUESTED_WITH'] = 'NotComponent' 
     59    assert !@request.component_call? 
     60 
     61    @request.env['HTTP_X_REQUESTED_WITH'] = 'ComponentCall' 
     62    assert @request.component_call? 
     63  end 
     64 
    5565  def test_subdomains 
    5666    @request.host = "www.rubyonrails.org" 
    5767    assert_equal %w( www ), @request.subdomains 
  • actionpack/lib/action_controller/components.rb

    old new  
    5252       
    5353      def request_for_component(options) 
    5454        request_for_component = @request.dup 
     55        request_for_component.env['HTTP_X_REQUESTED_WITH'] = 'ComponentCall' 
    5556        request_for_component.send( 
    5657          :instance_variable_set, :@parameters,  
    5758          (options[:params] || {}).merge({ "controller" => options[:controller], "action" => options[:action], "id" => options[:id] }).with_indifferent_access 
  • actionpack/lib/action_controller/request.rb

    old new  
    8686    end 
    8787    alias xhr? :xml_http_request? 
    8888 
     89    # Returns true if the request's "X-Requested-With" header constains 'ComponentCall' 
     90    def component_call? 
     91      not /ComponentCall/i.match(env['HTTP_X_REQUESTED_WITH']).nil? 
     92    end 
     93 
    8994    # Determine originating IP address.  REMOTE_ADDR is the standard 
    9095    # but will fail if the user is behind a proxy.  HTTP_CLIENT_IP and/or 
    9196    # HTTP_X_FORWARDED_FOR are set by proxies so check for these before 
  • actionpack/lib/action_controller/base.rb

    old new  
    270270    # has been rendered through response.body -- useful for <tt>after_filter</tt>s that wants to manipulate the output, 
    271271    # such as a OutputCompressionFilter. 
    272272    attr_accessor :response 
    273      
     273 
    274274    # Holds a hash of objects in the session. Accessed like <tt>session[:person]</tt> to get the object tied to the "person" 
    275275    # key. The session will hold any type of object as values, but the key should be a string. 
    276276    attr_accessor :session 
  • actionpack/lib/action_controller/flash.rb

    old new  
    143143   
    144144      # marks flash entries as used and expose the flash to the view  
    145145      def fire_flash 
     146        return if @request.component_call? 
    146147        flash.discard 
    147148        @assigns["flash"] = flash 
    148149      end 
    149150   
    150151      # deletes the flash entries that were not marked for keeping 
    151152      def sweep_flash 
     153        return if @request.component_call? 
    152154        flash.sweep 
    153155      end   
    154156  end