Lee Smith
2009-Oct-27 19:13 UTC
Re-tasking destroy contoller action...is this bad practice?
I''m trying to get some opinions on a design I''m floating ("rails way" or not?). Say I''ve got an Author model in my Blog application and I want my administrators to be able to disable authors. I don''t want to delete authors because this would cause data integrity issues (orphaned Author foreign key in the Post model). So my plan is to re- task the destroy method of the AuthorsContoller to allow an administrator to set a disabled_at timestamp on an Author instead of actually deleting him. What are the disadvantages to this design? One of the advantages to this design that I see is that I don''t have to declare a new controller method in my routes...it just fits into the REST design as is, no? Thanks for any advice.
Marnen Laibow-Koser
2009-Oct-27 19:22 UTC
Re: Re-tasking destroy contoller action...is this bad practice?
Lee Smith wrote:> I''m trying to get some opinions on a design I''m floating ("rails way" > or not?). Say I''ve got an Author model in my Blog application and I > want my administrators to be able to disable authors. I don''t want to > delete authors because this would cause data integrity issues > (orphaned Author foreign key in the Post model). So my plan is to re- > task the destroy method of the AuthorsContoller to allow an > administrator to set a disabled_at timestamp on an Author instead of > actually deleting him. >You might want to do this by overriding Author#destroy instead, as acts_as_paranoid does. That should make things a bit more airtight.> What are the disadvantages to this design? One of the advantages to > this design that I see is that I don''t have to declare a new > controller method in my routes...it just fits into the REST design as > is, no? Thanks for any advice.Seems OK to me. REST is about conceptual naming, not your implementation. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Lee Smith
2009-Oct-27 19:54 UTC
Re: Re-tasking destroy contoller action...is this bad practice?
Ah, so simply redefining the destroy method in the model accomplishes this? Is it just another public method? I don''t think I''ve ever overridden an activerecord method before...
Marnen Laibow-Koser
2009-Oct-27 21:20 UTC
Re: Re-tasking destroy contoller action...is this bad practi
Lee Smith wrote:> Ah, so simply redefining the destroy method in the model accomplishes > this?I would think so.> Is it just another public method?Yes.> I don''t think I''ve ever > overridden an activerecord method before...It might actually be better to use alias_method_chain, now that I think about it. Or just install acts_as_paranoid. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Lee Smith
2009-Oct-28 04:42 UTC
Re: Re-tasking destroy contoller action...is this bad practi
Yeah, I started to install acts_as_paranoid but I read that it''s not really updated anymore and may not even work with newer versions of Rails? I also looked at a revamped version of acts_as_paranoid called is_paranoid that is supposed to use named_scopes but now it looks like it has been abandoned by it''s author. Which led me to roll my own...
Marnen Laibow-Koser
2009-Oct-28 12:47 UTC
Re: Re-tasking destroy contoller action...is this bad practi
Lee Smith wrote:> Yeah, I started to install acts_as_paranoid but I read that it''s not > really updated anymore and may not even work with newer versions of > Rails?Huh? The repository on Github was last updated in April 2009.> I also looked at a revamped version of acts_as_paranoid called > is_paranoid that is supposed to use named_scopes but now it looks like > it has been abandoned by it''s author. > > Which led me to roll my own...I''ve never used acts_as_paranoid, but I think many people still use it, and the last update is recent enough that I assume it would work with Rails 2.3. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.