{"id":748,"date":"2022-08-30T15:06:31","date_gmt":"2022-08-30T15:06:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/undefined-method-parent-for-nilnilclass-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:06:31","modified_gmt":"2022-08-30T15:06:31","slug":"undefined-method-parent-for-nilnilclass-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/undefined-method-parent-for-nilnilclass-collection-of-common-programming-errors\/","title":{"rendered":"undefined method `parent&#39; for nil:NilClass-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m getting this strange error using Rails 3.0.2.<\/p>\n<pre><code>ActionView::Template::Error (undefined method `parent' for nil:NilClass):\napp\/controllers\/channels_controller.rb:19:in `index'\n<\/code><\/pre>\n<p>This is the controller, and line <code>19<\/code> is the <code>respond_with(@channels)<\/code> block.<\/p>\n<p>Where do I start to search for errors?<\/p>\n<pre><code>class ChannelsController &lt; ApplicationController\n  before_filter :set_default_client\n  respond_to :html, :xml\n\n  def index\n    if params[:cache_set]\n      @channels = Channel.active.find_all_by_id(params[:cache_set])\n    else\n      @channels = Channel.active.find_all_by_id(cookies[:channels].split(','))\n    end\n\n    respond_with(@channels)\n  end\nend\n<\/code><\/pre>\n<p>This is the full error:<\/p>\n<pre><code>ActionView::Template::Error (undefined method `parent' for nil:NilClass):\n  app\/controllers\/channels_controller.rb:19:in `index'\n\nRendered \/Users\/linus\/.rvm\/gems\/ruby-1.8.7-p330\/gems\/actionpack-3.0.2\/lib\/action_dispatch\/middleware\/templates\/rescues\/_trace.erb (1.3ms)\nRendered \/Users\/linus\/.rvm\/gems\/ruby-1.8.7-p330\/gems\/actionpack-3.0.2\/lib\/action_dispatch\/middleware\/templates\/rescues\/_request_and_response.erb (19.8ms)\nRendered \/Users\/linus\/.rvm\/gems\/ruby-1.8.7-p330\/gems\/actionpack-3.0.2\/lib\/action_dispatch\/middleware\/templates\/rescues\/template_error.erb within rescues\/layout (28.6ms)\n<\/code><\/pre>\n<p>I&#8217;m using Ruby 1.8.7 with Rails 3.0.2. I&#8217;ve also, just in case, tried Rails 3.0.7 and 3.0.0.<\/p>\n<ol>\n<li>\n<p>I solved the problem by changing HAML version from 3.1.x to 3.0.24.<\/p>\n<p>My new Gemfile looks like this.<\/p>\n<pre><code>gem \"rails\", \"3.0.2\"\ngem \"haml\", \"3.0.24\"\ngem \"compass\", \"0.10.6\"\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Are you in any case using HAML?<\/p>\n<p>I just bumped into this as well and my colleague (who is not on Stackoverflow yet) found out that it was due to multiline comments in the view template<\/p>\n<pre><code>-#\n  = helper_method_1\n  = helper_method_2\n<\/code><\/pre>\n<\/li>\n<li>\n<p>It looks like HAML-edge has fixed this problem. I expect the next release of HAML after 3.1.1 to resolve this.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:30:32. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m getting this strange error using Rails 3.0.2. ActionView::Template::Error (undefined method `parent&#8217; for nil:NilClass): app\/controllers\/channels_controller.rb:19:in `index&#8217; This is the controller, and line 19 is the respond_with(@channels) block. Where do I start to search for errors? class ChannelsController &lt; ApplicationController before_filter :set_default_client respond_to :html, :xml def index if params[:cache_set] @channels = Channel.active.find_all_by_id(params[:cache_set]) else @channels = Channel.active.find_all_by_id(cookies[:channels].split(&#8216;,&#8217;)) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-748","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=748"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/748\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}