Undefined `parent 'method for nil: NilClass

I get this strange error using Rails 3.0.2.

ActionView::Template::Error (undefined method `parent' for nil:NilClass):
app/controllers/channels_controller.rb:19:in `index'

This is the controller, and the line 19is the block respond_with(@channels).

Where to start the search for errors?

class ChannelsController < 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(','))
    end

    respond_with(@channels)
  end
end

This is a complete error:

ActionView::Template::Error (undefined method `parent' for nil:NilClass):
  app/controllers/channels_controller.rb:19:in `index'

Rendered /Users/linus/.rvm/gems/ruby-1.8.7-p330/gems/actionpack-3.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /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)
Rendered /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)

I am using Ruby 1.8.7 with Rails 3.0.2. I also, just in case, tried Rails 3.0.7 and 3.0.0.

+5
source share
3 answers

I solved the problem by changing the HAML version from version 3.1.x to 3.0.24.

My new gemfile looks like this.

gem "rails", "3.0.2"
gem "haml", "3.0.24"
gem "compass", "0.10.6"
+2
source

Do you use HAML anyway?

I just ran into this, and my colleague (who is not already on Stackoverflow) found that this was due to multi-line comments in the view template

-#
  = helper_method_1
  = helper_method_2
+9

It seems that the HAML-edge issue fixed this issue. I look forward to the next release of HAML after 3.1.1 to solve this problem.

0
source

All Articles