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

Changeset 4860

Show
Ignore:
Timestamp:
08/30/06 00:34:36 (2 years ago)
Author:
xal
Message:

respond_to .html now always renders #{action_name}.rhtml so that registered custom template handlers do not override it in priority.
Custom mime types require a block and throw proper error now.

Files:

Legend:

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

    r4833 r4860  
    11*SVN* 
     2 
     3* respond_to .html now always renders #{action_name}.rhtml so that registered custom template handlers do not override it in priority. Custom mime types require a block and throw proper error now. [Tobias Luetke] 
    24 
    35* Deprecation: test deprecated instance vars in partials. [Jeremy Kemper] 
  • trunk/actionpack/lib/action_controller/base.rb

    r4755 r4860  
    2727  end 
    2828  class MissingFile < ActionControllerError #:nodoc: 
     29  end 
     30  class RenderError < ActionControllerError #:nodoc: 
    2931  end 
    3032  class SessionOverflowError < ActionControllerError #:nodoc: 
  • trunk/actionpack/lib/action_controller/mime_responds.rb

    r4759 r4860  
    109109     
    110110    class Responder #:nodoc: 
    111       DEFAULT_BLOCKS = { 
    112         :html    => 'Proc.new { render }', 
    113         :js      => 'Proc.new { render :action => "#{action_name}.rjs" }', 
    114         :xml     => 'Proc.new { render :action => "#{action_name}.rxml" }' 
    115       } 
     111      DEFAULT_BLOCKS = [:html, :js, :xml].inject({}) do |blocks, ext| 
     112        blocks.update ext => %(Proc.new { render :action => "\#{action_name}.r#{ext}" }) 
     113      end       
    116114       
    117115      def initialize(block_binding) 
     
    135133          @responses[mime_type] = block 
    136134        else 
    137           @responses[mime_type] = eval(DEFAULT_BLOCKS[mime_type.to_sym], @block_binding) 
     135          if source = DEFAULT_BLOCKS[mime_type.to_sym] 
     136            @responses[mime_type] = eval(source, @block_binding)             
     137          else 
     138            raise ActionController::RenderError, "Expected a block but none was given for custom mime handler #{mime_type}" 
     139          end 
    138140        end 
    139141      end 
  • trunk/actionpack/lib/action_controller/mime_type.rb

    r4622 r4860  
    3535        Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, synonyms) 
    3636        SET << Mime.send(:const_get, symbol.to_s.upcase) 
    37         LOOKUP[string] = EXTENSION_LOOKUP[symbol.to_s] = SET.last 
     37        LOOKUP[string] = EXTENSION_LOOKUP[symbol.to_s] = SET.last         
    3838      end 
    3939 
  • trunk/actionpack/test/controller/mime_responds_test.rb

    r4409 r4860  
    7373    Mime.send :remove_const, :MOBILE 
    7474  end 
     75   
     76  def custom_constant_handling_without_block 
     77    Mime::Type.register("text/x-mobile", :mobile) 
     78 
     79    respond_to do |type| 
     80      type.html   { render :text => "HTML"   } 
     81      type.mobile 
     82    end 
     83     
     84    Mime.send :remove_const, :MOBILE     
     85  end 
     86   
    7587 
    7688  def handle_any 
     
    272284  end 
    273285   
     286  def custom_constant_handling_without_block 
     287     
     288    assert_raised(ActionController::RenderError) do 
     289      get :custom_constant_handling, :format => "mobile" 
     290    end 
     291  end 
     292   
    274293  def test_forced_format 
    275294    get :html_xml_or_rss