Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

action_controller layout candidate for layout fails

#2442

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

Reported by ransom-briggs (at uiowa) · April 7th, 2009 @ 04:18 PM

State: stale
Milestone: 3.x
Assigned to: Sven Fuchs Sven Fuchs
Importance: none

Activity

  1. ransom-briggs (at uiowa)
  2. ransom-briggs (at uiowa)
    ransom-briggs (at uiowa)
    • Assigned user set to Sven Fuchs

    assigned to most recent committer

    April 7th, 2009 @ 04:30 PM

  3. Paul Hinze
    Paul Hinze

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

    April 7th, 2009 @ 04:39 PM

  4. thedarkone
    thedarkone

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

    April 7th, 2009 @ 10:07 PM

  5. ransom-briggs (at uiowa)
    ransom-briggs (at uiowa)

    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

    April 7th, 2009 @ 10:52 PM

  6. ransom-briggs (at uiowa)
    ransom-briggs (at uiowa)

    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 }

    April 8th, 2009 @ 02:05 PM

  7. ransom-briggs (at uiowa)
    ransom-briggs (at uiowa)

    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?.

    April 8th, 2009 @ 02:07 PM

  8. Matt Dean
    Matt Dean

    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).

    June 2nd, 2009 @ 06:46 PM

  9. Derrick Spell
    Derrick Spell

    +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.

    June 2nd, 2009 @ 06:52 PM

  10. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  11. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:39 PM

  12. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:39 PM