We have used acts_as_paranoid gem(https://github.com/ActsAsParanoid/acts_as_paranoid) for soft deletion in our project. The project is in live now. Faced some of the issues in this gem and planned to migrate to paranoia gem(https://github.com/rubysherpas/paranoia). Is there anything we need to consider while migrating?
I would recommend taking a look at Discard
https://github.com/jhawthorn/discard#why-not-paranoia-or-acts_as_paranoid
It accomplishes a similar goal without overriding activerecord's method by taking a simpler approach of providing convenience methods to hide soft-deleted records. There is a section on the documentation about why the author thiks this is better than either acts-as-paranoid or paranoia.
Related
I am new to RoR. I met one question which is: some active records may not needed to be searched for in database(let's say they are expired). I don't want to delete it from database because it is associated with other models. Also since it is expired, I don't want it to be updated. Is there any way to handle this situation in rails?
A Rails plugin to add soft delete.
This gem can be used to hide records instead of deleting them, making them recoverable later.
https://github.com/ActsAsParanoid/acts_as_paranoid
There are different ways. But I recommend you to use https://github.com/radar/paranoia
You can find a good screencast here: https://gorails.com/episodes/soft-delete-with-paranoia
It is really easy to add to your app. Just add the gem to your Gemfile and add acts_as_paranoid to your model.
Your question(s)
Avoid querying a subset of your data:
*For this one ought to utilize ActiveRecord's scopes. Specifically use a default scope. Ref here http://api.rubyonrails.org/classes/ActiveRecord/Scoping/Default/ClassMethods.html. Incidentally, this is the mechanism that the soft-delete gems I have come across utilize to hide soft-delete records
How to prevent updating the records:
Not sure how you mean. What about the records that you are not going to be using will be (automatically?) updated?
We are planning to make some of the tables audit enabled in our Rails3 application. We did look at paper_trail and it seems to store all the versions, but I wasn't sure if there was a mechanism to find the difference b/w what field changed within successive versions. Would it be possible to do with the paper_trail gem or should I use something like vestal_versions for this capability?
You can achieve that with paper_tail gem. If you add an object_changes text column to your versions table, you can use the version.changeset method to retrieve it. If you haven't yet, I recommend going through 'Diffing Versions' section in https://github.com/airblade/paper_trail
p.s. I am using paper_trail in one of my projects currently.
What's the standard/best option out there for this kind of version control? The main thing I'm looking for is to track what user edited a record.
I've seen these so far and am wondering what your take is:
PaperTrail
ActsAsAudited
VestalVersions
The plugins you mentioned all seem to take the same approach, and seem to be somewhat similar in approach: use a seperate table to store the old versions.
None of them seem to be really rails3-ready (looking at the generators), but PaperTrail reportedly should work with rails3, and has the most recent commit.
You could also look at the ruby-toolbox user-stamping and versioning. There you can see which project has the most "traction", which has the most recent commits. Which sometimes can help to make a choice between similar options.
For stamping user_ids onto rows there is the the userstamp plugin
http://github.com/delynn/userstamp
EDIT:
Based on the requirement mentioned in your comment, I would recommend act_as_audited
http://github.com/collectiveidea/acts_as_audited
We are using it successfully for a very large application.
Peer
I think PaperTrail is what you need to solve this problem.
With PaperTrail you can track and see all changes ,to any model, with user id of who made the changes.
It is currently the best maintained project of the three you linked
HI #viatropos I thought that these two links might prove to be helpful
http://api.rubyonrails.org/classes/ActiveRecord/Observer.html
http://www.robbyonrails.com/articles/2007/04/27/observers-big-and-small
I'd like to be sure if vestal_versions does support versioned associations (it seems like it doesn't) before switching out to another versioning gem that can support versioned associations e.g => has_versioning. I haven't looked at the code yet but I couldn't find anything related with versioned associations from the readme file or the issue section on github. Help would be appreciated!
(At the moment of writing this) There is an associations branch in the official vestal_versions repository, It is still a basic idea and isn't merged yet in the master branch. So I decided to go with another versioning gem, specifically acts_as_revisable following the instructions in this blog post.
I'm looking for something that appears to be very close to your needs. But I don't need to revert the associated objects, just to record them. I was thinking of handle it in a nosql way. So I can save the model version and the associations would be embedded documents.
So I can compare versions in a more comprehensive way. Right now I use paper_trail, but as it can't handle associations, it's not possible to store the tags associated to a model and see how it changes through time.
I'm looking for a rails plugin/gem which brings the functionality of marking an ActiveRecord-Model deleted, instead of deleteing it.
Does anybody know, what gems or plugins are up to date? (AAP is out-dated and is_paranoid doesn't appear to be used by the community).
Do you know alternatives?
It seems even the authors of both acts_as_paranoid and is_paranoid aren't using their respective plugins/gems any more. Both are using named scopes.
Yeah, it's not automagic or anything, but sometimes being explicit about your intentions is a good thing.
For completeness, here is a more recent gem for this purpose:
Paranoia - acts_as_paranoid for Rails 3
https://github.com/radar/paranoia
And another:
https://github.com/JackDanger/permanent_records
is_paranoid doesn't appear to be used by the community..
http://chadfowler.com/blog/2009/07/08/how-ruby-mixins-work-with-inheritance/ - Just a blog post the other day talking about it. Seems like it solved Chad's problem just fine (as well as lead him to write a post about inheritance and mixins).
How about you just have a valid:boolean column/attribute and set it to false when you wish to soft-delete the model? Or am I missing something?