# After filter not working

**URL:** <https://www.ruby-forum.com/t/after-filter-not-working/139412>\
**Category:** Rails\
**Created:** [June 3, 2008, 5:39pm UTC](https://www.ruby-forum.com/t/after-filter-not-working/139412 "2008-06-03T17:39:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [June 3, 2008, 5:39pm UTC](https://www.ruby-forum.com/t/after-filter-not-working/139412/1 "2008-06-03T17:39:18Z")

</div>

I have a simple “after\_filter” that is supposed to remove “child”  
records from one table (folders\_tbl) when the parent is deleted from  
another table (courses\_tbl). It’s not working. The “course” gets  
destroyed but the children “folders” do not. Filters aren’t that  
complicated but I don’t understand why this isn’t working. I’ve  
included snipplets below. Any ideas?

**–course controller–**  
after\_filter :courseCleanUp, :only =\> :delete

# DELETE /courses/1

def destroy  
@course = Course.find(params[:id])  
@course.destroy  
respond\_to do |format|  
format.html { redirect\_to :action =\> :index }  
end  
end

protected

def courseCleanUp  
Folder.destroy\_all([“course\_id = ?”, session[:course\_id]])  
end

---

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [June 3, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/after-filter-not-working/139412/2 "2008-06-03T17:43:53Z")

</div>

On 3 Jun 2008, at 16:39, Corey M. wrote:

> 

the :only needs to be the action\_name (ie :destroy). I’d also  
recommend that the controller know absolutely nothing about this (use  
callbacks, :dependent =\> :destroy etc…)

Fred

---

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [June 3, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/after-filter-not-working/139412/3 "2008-06-03T18:03:10Z")

</div>

Frederick C. wrote:

> On 3 Jun 2008, at 16:39, Corey M. wrote:
> 
> > 
> 
> the :only needs to be the action\_name (ie :destroy). I’d also  
> recommend that the controller know absolutely nothing about this (use  
> callbacks, :dependent =\> :destroy etc…)
> 
> Fred

Thanks for the ideas. I’ve gone to using the “after\_destroy” call back  
in the model and it worked great.

Thanks again
