# Cache sweeping and render\_component (my mistake or Rails bug

**URL:** <https://www.ruby-forum.com/t/cache-sweeping-and-render-component-my-mistake-or-rails-bug/68479>\
**Category:** Rails\
**Created:** [September 13, 2006, 12:50am UTC](https://www.ruby-forum.com/t/cache-sweeping-and-render-component-my-mistake-or-rails-bug/68479 "2006-09-13T00:50:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrzej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f17d59/32.png) [@andrzej](https://www.ruby-forum.com/u/andrzej)\
**Post date:** [September 13, 2006, 12:50am UTC](https://www.ruby-forum.com/t/cache-sweeping-and-render-component-my-mistake-or-rails-bug/68479/1 "2006-09-13T00:50:13Z")

</div>

Hi

I’m working on a program which relies on heavy cache sweeper usage.  
I’ve just bumped onto an odd problem. When using render\_component  
method in layouts or templates with cache sweeping turned on, Rails  
throws an exception with the following message:

NoMethodError in TestController#index

You have a nil object when you didn’t expect it!  
The error occured while evaluating nil.controller\_name

where TestController is obviously my controller class name. I’m running  
Rails 1.1.6 on linux box. My test app which extracts the error consists  
of a controller which body is only:

require ‘sweeper’  
class TestController \< ApplicationController  
cache\_sweeper :sweeper

def index  
end

def foo  
render :text =\> “foo”  
end  
end

The file sweeper.rb contains my sweeper class definition:  
class Sweeper \< ActionController::Caching::Sweeper  
observe Bar  
end  
Bar is an empty model, with a table bars containing only id field.  
I’ve turned the caching on by setting  
config.action\_controller.perform\_caching = true in  
config/development/environment.rb file.

Exception is thrown in  
actionpack-1.12.5/lib/action\_controller/caching.rb file in line 541.  
Am I doing something wrong or it’s some kind of a Rails bug?

---

<div class="post-metadata">

**Author:** ![andrzej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f17d59/32.png) [@andrzej](https://www.ruby-forum.com/u/andrzej)\
**Post date:** [March 27, 2007, 6:20am UTC](https://www.ruby-forum.com/t/cache-sweeping-and-render-component-my-mistake-or-rails-bug/68479/2 "2007-03-27T06:20:08Z")

</div>

Andrzej, have you found the solution to this? I’m facing similar issue.  
Thanks.

---

<div class="post-metadata">

**Author:** ![andrzej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f17d59/32.png) [@andrzej](https://www.ruby-forum.com/u/andrzej)\
**Post date:** [April 7, 2007, 9:00pm UTC](https://www.ruby-forum.com/t/cache-sweeping-and-render-component-my-mistake-or-rails-bug/68479/3 "2007-04-07T21:00:22Z")

</div>

> Andrzej, have you found the solution to this? I’m facing similar issue.

Yes, I got rid of render\_component. Unfortunately that’s probably not  
the kind of answer you’d like to see. Component caching was broken in  
Rails 1.1.6 and I haven’t checked it’s behavior in later versions.  
Should you come up with a means of fixing the problem in question,  
please let me know;)

regards  
Andrzej Zawadzki
