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.
Lee S. 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
[email protected]
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…
Lee S. 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
[email protected]
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…
Lee S. 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
[email protected]