{"id":1883,"date":"2013-01-04T15:49:43","date_gmt":"2013-01-04T04:49:43","guid":{"rendered":"https:\/\/www.spiffystores.com.au\/blog\/?p=1883"},"modified":"2021-09-01T07:17:16","modified_gmt":"2021-08-31T21:17:16","slug":"problems-rendering-a-layout-in-rails3","status":"publish","type":"post","link":"https:\/\/www.spiffystores.com.au\/blog\/2013\/01\/04\/problems-rendering-a-layout-in-rails3\/","title":{"rendered":"Problems rendering a layout in Rails3"},"content":{"rendered":"\n<p>From time to time we like to share technical tips when we&#8217;ve uncovered a solution to a problem that might help other Rails developers.<\/p>\n\n\n\n<p>Spiffy Stores is written using the Ruby on Rails framework, and we encountered a glitch with the Rails3 layouts. Basically we couldn&#8217;t get the layout to display, even though all the syntax was correct. Others have experienced this sort of problem. See <a href=\"http:\/\/stackoverflow.com\/questions\/6605716\/cant-render-layout-in-rails-3\" target=\"_blank\" rel=\"noopener\">http:\/\/stackoverflow.com\/questions\/6605716\/cant-render-layout-in-rails-3<\/a> for an example.<\/p>\n\n\n\n<p>After lots of digging around and tracing, the answer became clear. The AbstractController::Layouts module has an initialize method, but this method was not being called when a new controller was created.<\/p>\n\n\n\n<p>If you experience this problem, then check any modules that you have included in your controller, as one of them has an initialize method that doesn&#8217;t call &#8216;super&#8217;.<\/p>\n\n\n\n<p>If an included module needs an initialize method, then it needs to follow this pattern:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"ruby\" class=\"language-ruby\">def initialize(*)\n  # Module initialization code here\n  super\nend<\/code><\/pre>\n\n\n\n<p>If the call to &#8216;super&#8217; isn&#8217;t included, then the initialization chain stops, and your controller won&#8217;t be properly initialized. You can find out all the included modules for a controller by executing this code from the console:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"ruby\" class=\"language-ruby\">MyController.ancestors<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>From time to time we like to share technical tips when we&#8217;ve uncovered a solution to a problem that might help other Rails developers. Spiffy Stores is written using the Ruby on Rails framework, and we encountered a glitch with &hellip; <a href=\"https:\/\/www.spiffystores.com.au\/blog\/2013\/01\/04\/problems-rendering-a-layout-in-rails3\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[218,216,215,12,220,214,11,219,217],"class_list":["post-1883","post","type-post","status-publish","format-standard","hentry","category-geek-stuff","tag-controller","tag-initialize","tag-layout","tag-rails","tag-rails-3","tag-rails3","tag-ruby","tag-ruby-on-rails","tag-super"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pgk4DF-un","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/posts\/1883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/comments?post=1883"}],"version-history":[{"count":1,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/posts\/1883\/revisions"}],"predecessor-version":[{"id":3235,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/posts\/1883\/revisions\/3235"}],"wp:attachment":[{"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/media?parent=1883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/categories?post=1883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spiffystores.com.au\/blog\/wp-json\/wp\/v2\/tags?post=1883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}