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

Ticket #9564: default_layouts_with_register_alias.patch

File default_layouts_with_register_alias.patch, 1.9 kB (added by lifofifo, 1 year ago)
  • actionpack/test/controller/mime_responds_test.rb

    old new  
    116116   
    117117  def iphone_with_html_response_type  
    118118    Mime::Type.register_alias("text/html", :iphone) 
    119  
     119    request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone" 
     120     
    120121    respond_to do |type| 
    121122      type.html   { @type = "Firefox" } 
    122123      type.iphone { @type = "iPhone"  } 
  • actionpack/lib/action_controller/layout.rb

    old new  
    234234 
    235235    protected 
    236236      def render_with_a_layout(options = nil, &block) #:nodoc: 
    237         if template_with_options = options.is_a?(Hash) 
    238           response.template.template_format = options[:content_type].to_sym if options[:content_type] 
    239         end 
    240  
     237        template_with_options = options.is_a?(Hash) 
     238        set_template_format(options) 
     239         
    241240        if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options)) 
    242241          assert_existence_of_template_file(layout) 
    243242 
     
    307306          self.class.send(:layout_directory_exists_cache)[File.dirname(template_path)] 
    308307        end 
    309308      end 
     309       
     310      def set_template_format(options) 
     311        if options.is_a?(Hash) && options[:content_type] 
     312          response.template.template_format = options[:content_type].to_sym  
     313        elsif params[:format] 
     314          response.template.template_format = Mime::Type.lookup(Mime::Type.lookup_by_extension(params[:format]).to_s).to_sym 
     315        end 
     316      end 
    310317  end 
    311318end