noded noded - 1 year ago 54
Ruby Question

Model to implement users (Ruby on Rails 3)

I am implementing a User that is not actually deleted from the system with destroy but only marked with

:active = false

The problem here is that such an inactivate user will show up in all
, ... calls. I don't want to pollute the code with all kinds of 'if-else's or overwriting the behavior of

I just want to know whether I can nicely define it within the User's model so that inactive users will virtually disappear unless I explicitly want to extract such a user.

If there is no way to do it in the model then what are my options?

Answer Source

I think you may want to check acts_as_paranoid Here is a link for one of the implementations:

From the wiki:

Now whenever destroy is called on that model, it is just removed from view and the deleted_at column set to the current date time. All the finder methods ignore “deleted” records.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download