This project is archived and is in readonly mode.

#3967 ✓stale
Rudolf Gavlas

verify with render[:layout] and cache_classes broken

Reported by Rudolf Gavlas | February 15th, 2010 @ 05:59 PM

With configuration option

  config.cache_classes = true
will a controller's verify with specified render[:layout] use this layout only once, the second time this verify block renders is going to be used the default layout for the controller.

Example:

1) set

  config.cache_classes = true

2) add to your controller

  verify(:only => ['test'], :params => :foo, :render => {:template => 'bar/baz', :layout => 'lay0'})
  layout 'lay1'
3) setup different layouts lay0, lay1
4) request the test action twice in a row from the server and see, what is being rendered

The first time it will render the lay0 layout, second and all other times it will render the defaul layout lay1.

It's because the code in actionpack/lib/action_controller/layout.rb:

    def pick_layout(options)
    if options.has_key?(:layout)
      case layout = options.delete(:layout)
      when FalseClass
        nil
      when NilClass, TrueClass

-- note the "options.delete(:layout)".

You can get a picture what's going on if you freeze the render hash in actionpack/lib/action_controller/verification.rb:

    --- verification.rb.orig        2010-02-15 16:34:33.000000000 +0100

+++ verification.rb     2010-02-15 18:15:23.000000000 +0100
@@ -80,6 +80,7 @@
       #   array (may also be a single value).
       def verify(options={})
         before_filter :only => options[:only], :except => options[:except] do |c|
+          options[:render].freeze if options[:render]
           c.__send__ :verify_action, options
         end
       end



Workaround: instad of

  verify(:only => ['test'], :params => :foo, :render => {:template => 'bar/baz', :layout => 'lay0'})

use:

    before_filter :verify_foo, :only => ['test']

private

def verify_foo
  verify_action({:params => :foo, :render => {:template => 'bar/baz', :layout => 'lay0'}})
end</code>



One of the possible solutions is passing on a deep copy of the options passed to verify (see the attached patch).

Comments and changes to this ticket

  • Andrea Campi

    Andrea Campi October 16th, 2010 @ 11:53 PM

    • Tag changed from cache_classes, layout, rails-2.3, render, verify to 2-3-stable, cache_classes, layout, render, verify
  • Santiago Pastorino

    Santiago Pastorino February 9th, 2011 @ 12:31 AM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 9th, 2011 @ 12:31 AM

    • State changed from “open” to “stale”
  • Rudolf Gavlas

    Rudolf Gavlas February 9th, 2011 @ 01:28 AM

    Hello, Santiago. I am not going to try to reproduce this on 3-0-stable or master, my resources are limited as well and i already spent a lot of time with my original report without getting any response. FWIW i just made a cursory check of the code of 3-0-stable and i see a similar idiom there as what seems to be the source of problems in 2.3-stable: https://github.com/rails/rails/blob/3-0-stable/actionpack/lib/abstr... (but i can't say if this could be problematic in 3.x or not).

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages