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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 3 Jun 2008, at 16:39, Corey Murphy wrote:> > 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 >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> # 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 > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 3 Jun 2008, at 16:39, Corey Murphy 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...) > > FredThanks for the ideas. I''ve gone to using the "after_destroy" call back in the model and it worked great. Thanks again -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---