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

Changeset 1369

Show
Ignore:
Timestamp:
05/30/05 07:51:02 (3 years ago)
Author:
minam
Message:

render(:text), render(:partial), and render(:nothing) always default to :layout => false. This also fixes send_file, which was applying a layout if one existed for the current action.

Files:

Legend:

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

    r1367 r1369  
    11*SVN* 
     2 
     3* render(:text), render(:partial), and render(:nothing) always default to :layout => false. This also fixes send_file, which was applying a layout if one existed for the current action. 
    24 
    35* verify with :redirect_to won't redirect if a redirect or render has already been performed #1350 
  • trunk/actionpack/lib/action_controller/layout.rb

    r1353 r1369  
    145145    # If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above. 
    146146    # Some times you'll have exceptions, though, where one action wants to use a different layout than the rest of the controller. 
    147     # This is possible using <tt>render_with_layout</tt> method. It's just a bit more manual work as you'll have to supply fully 
     147    # This is possible using the <tt>render</tt> method. It's just a bit more manual work as you'll have to supply fully 
    148148    # qualified template and layout names as this example shows: 
    149149    # 
    150150    #   class WeblogController < ActionController::Base 
    151151    #     def help 
    152     #       render_with_layout "help/index", "200", "layouts/help" 
     152    #       render :file => "help/index", :layout => "layouts/help" 
    153153    #     end 
    154154    #   end 
     
    204204 
    205205    def render_with_a_layout(options = {}, deprecated_status = nil, deprecated_layout = nil) #:nodoc: 
    206       if (layout = pick_layout(options, deprecated_layout)) && options.is_a?(Hash) && options[:text] 
     206      options = render_with_a_layout_options(options) 
     207      if (layout = pick_layout(options, deprecated_layout)) 
    207208        logger.info("Rendering #{options[:template]} within #{layout}") unless logger.nil? 
    208209 
     
    218219 
    219220    private 
     221      def render_with_a_layout_options(options) 
     222        return options unless options.is_a?(Hash) 
     223        case 
     224        when options[:text], options[:partial], options[:nothing] 
     225          # by default, :text, :partial, and :nothing never use a layout 
     226          { :layout => false }.merge(options) 
     227        else 
     228          options 
     229        end 
     230      end 
     231 
    220232      def pick_layout(options = {}, deprecated_layout = nil) 
    221         return deprecated_layout if !deprecated_layout.nil? || (options.is_a?(Hash) && options[:nothing]) 
     233        return deprecated_layout if !deprecated_layout.nil? 
    222234 
    223235        if options.is_a?(Hash) 
  • trunk/actionpack/test/controller/new_render_test.rb

    r1366 r1369  
    7474  def partial_only 
    7575    render :partial => true 
     76  end 
     77 
     78  def partial_only_with_layout 
     79    render :partial => "partial_only", :layout => nil 
    7680  end 
    7781 
     
    9094    def determine_layout 
    9195      case action_name  
    92         when "layout_test", "rendering_without_layout", "rendering_nothing_on_layout" 
     96        when "layout_test", "rendering_without_layout", 
     97             "rendering_nothing_on_layout", "render_text_hello_world", 
     98             "partial_only", "partial_only_with_layout" 
    9399          "layouts/standard" 
    94100        when "builder_layout_test" 
     
    220226  end 
    221227 
     228  def test_partial_only_with_layout 
     229    get :partial_only_with_layout 
     230    assert_equal "<html>only partial</html>", @response.body 
     231  end 
     232 
    222233  def test_render_to_string 
    223234    get :hello_in_a_string 
  • trunk/actionpack/test/controller/send_file_test.rb

    r400 r1369  
    1111class SendFileController < ActionController::Base 
    1212  include TestFileUtils 
     13  layout "layouts/standard" # to make sure layouts don't interfere 
    1314 
    1415  attr_writer :options 
     
    2122end 
    2223 
     24SendFileController.template_root = File.dirname(__FILE__) + "/../fixtures/" 
    2325 
    2426class SendFileTest < Test::Unit::TestCase