This project is archived and is in readonly mode.

#2442 ✓stale
ransom-briggs (at uiowa)

action_controller layout candidate for layout fails

Reported by ransom-briggs (at uiowa) | April 7th, 2009 @ 04:18 PM | in 3.x

The default layout does not render for us correctly after 2.3 because the pick_layout method returns nil. This is due to the fact that candidate_for_layout returns incorrect output if no :action key is passed in options hash. default_template will default to self.action_name, but if the :action key isn't in options it will be passed nil and then fail.

Our local fix is as follows...

actionpack/lib/action_controller/layout.rb
       def candidate_for_layout?(options)
-        template = options[:template] || default_template(options[:action])
+        if options.has_key?(:action)
+          template = options[:template] || default_template(options[:action])
+        else
+          template = options[:template] || default_template()
+        end

Comments and changes to this ticket

  • ransom-briggs (at uiowa)
  • ransom-briggs (at uiowa)

    ransom-briggs (at uiowa) April 7th, 2009 @ 04:30 PM

    • Assigned user set to “Sven Fuchs”

    assigned to most recent committer

  • Paul Hinze

    Paul Hinze April 7th, 2009 @ 04:39 PM

    I can confirm that this is a problem and that the patch supplied seems to solve it.

  • thedarkone

    thedarkone April 7th, 2009 @ 10:07 PM

    When exactly does this happen (so we can also add a test case)?

  • ransom-briggs (at uiowa)

    ransom-briggs (at uiowa) April 7th, 2009 @ 10:52 PM

    vendor/plugins/footnotes-edge/lib/textmate_initialize.rb does not play well with 2.3

    8 def render(options = {}, deprecated_status = {}, &block) #:doc: 9 if options.is_a? Hash 10 @render_without_footnotes = (options.delete(:footnotes) == false) 11 end => 12 footnotes_original_render(options, deprecated_status, &block) 13 end

    the options = {} causes the {} to be passed down - if it doesn't to through footnotes-edge then it gets initialized to nil in

    44 def render_with_benchmark(options = nil, extra_options = {}, &block)

    and then render sets a sane :template parameter which is used

    891 def render(options = nil, extra_options = {}, &block) #:doc: 892 raise DoubleRenderError, "Can only render or redirect once per action" if performed? 893 894 validate_render_arguments(options, extra_options, block_given?) 895 896 if options.nil? 897 options = { :template => default_template, :layout => true }

    so we will just stop using footnotes edge since no one in our group will miss it

  • ransom-briggs (at uiowa)

    ransom-briggs (at uiowa) April 8th, 2009 @ 02:05 PM

    another way to fix this would be to change line 896 in

    vendor/rails/actionpack/lib/action_controller/base.rb

    891 def render(options = nil, extra_options = {}, &block) #:doc: 892 raise DoubleRenderError, "Can only render or redirect once per action" if performed? 893 894 validate_render_arguments(options, extra_options, block_given?) 895 896 if options.nil? 897 options = { :template => default_template, :layout => true }

    891 def render(options = nil, extra_options = {}, &block) #:doc: 892 raise DoubleRenderError, "Can only render or redirect once per action" if performed? 893 894 validate_render_arguments(options, extra_options, block_given?) 895 896 if options.nil? || options.empty? 897 options = { :template => default_template, :layout => true }

  • ransom-briggs (at uiowa)

    ransom-briggs (at uiowa) April 8th, 2009 @ 02:07 PM

    sorry - I need to learn the formatting language of lighthouse better, my suggestion was that in the render method, the options.nil? section should also be used when options is empty?.

  • Matt Dean

    Matt Dean June 2nd, 2009 @ 06:46 PM

    I also came across this problem in the following use case:

    def show
    
      options = {}
    
      returning choose_template do |template|
        options[:template] = template unless template.blank?
      end
    
      render options
    
    end
    

    While there are certainly alternate approaches for fixing this on our end, the "options.nil? || options.empty?" approach recommended by ransom-briggs above did the trick for us (though we used options.blank? instead).

  • Derrick Spell

    Derrick Spell June 2nd, 2009 @ 06:52 PM

    +1 for using options.blank? instead of options.nil?. Although doing (options.nil? || options.empty?) does indeed do the same thing and might arguably be more explanatory.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:39 PM

    • State changed from “new” to “open”
    • Importance changed from “” to “”

    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 2nd, 2011 @ 04:39 PM

    • State changed from “open” to “stale”

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>

Attachments

Pages