I'm getting 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 line 19
is the respond_with(@channels)
block.
Where do I start to 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 the full 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'm using Ruby 1.8.7 with Rails 3.0.2. I've also, just in case, tried Rails 3.0.7 and 3.0.0.
The Undefined method for nil:NILClass occurs when you attempt to use a formula on a blank datapill. This indicates that the datapill was not provided any value at runtime.
Explained. This is a common Ruby error which indicates that the method or attribute for an object you are trying to call on an object has not been defined.
What is an undefined method in Ruby? Undefined method call created a NoMethodError. This is a typical Ruby error that indicates that the method or attribute you are attempting to call on an object has not been declared.
Undefined instance variables are always nil , so you want to check for that. Try the “safe navigator operator” (Ruby 2.3+) which only calls a method if the variable is not nil .
Are you in any case using HAML?
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
-#
= helper_method_1
= helper_method_2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With