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

Changeset 7479

Show
Ignore:
Timestamp:
09/15/07 04:18:32 (1 year ago)
Author:
david
Message:

Fixed that setting request.format would also affect respond_to blocks [DHH]

Files:

Legend:

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

    r7478 r7479  
    11*SVN* 
     2 
     3* Fixed that setting request.format would also affect respond_to blocks [DHH] 
    24 
    35* Add option to force binary mode on tempfile used for fixture_file_upload.  #6380 [Jonathan Viney] 
  • trunk/actionpack/lib/action_controller/request.rb

    r7438 r7479  
    1212    # such as { 'RAILS_ENV' => 'production' }. 
    1313    attr_reader :env 
    14  
    15     # The requested content type, such as :html or :xml. 
    16     attr_writer :format 
    1714 
    1815    # The HTTP request method as a lowercase symbol, such as :get. 
     
    9087    def format 
    9188      @format ||= parameters[:format] ? Mime::Type.lookup_by_extension(parameters[:format]) : accepts.first 
     89    end 
     90     
     91     
     92    # Sets the format by string extension, which can be used to force custom formats that are not controlled by the extension. 
     93    # Example: 
     94    # 
     95    #   class ApplicationController < ActionController::Base 
     96    #     before_filter :adjust_format_for_iphone 
     97    #    
     98    #     private 
     99    #       def adjust_format_for_iphone 
     100    #         request.format = :iphone if request.env["HTTP_USER_AGENT"][/iPhone/] 
     101    #       end 
     102    #   end 
     103    def format=(extension) 
     104      parameters[:format] = extension.to_s 
     105      format 
    92106    end 
    93107 
  • trunk/actionpack/test/controller/mime_responds_test.rb

    r6856 r7479  
    3333      type.xml  { render :text => "XML"     } 
    3434      type.all  { render :text => "Nothing" } 
     35    end 
     36  end 
     37 
     38  def forced_xml 
     39    request.format = :xml 
     40 
     41    respond_to do |type| 
     42      type.html { render :text => "HTML"    } 
     43      type.xml  { render :text => "XML"     } 
    3544    end 
    3645  end 
     
    344353  end 
    345354 
     355  def test_internally_forced_format 
     356    get :forced_xml 
     357    assert_equal "XML", @response.body 
     358 
     359    get :forced_xml, :format => "html" 
     360    assert_equal "XML", @response.body 
     361  end 
     362 
    346363  def test_extension_synonyms 
    347364    get :html_xml_or_rss, :format => "xhtml"