Model Versioning in Rails

I am new to Rails / Ruby. I am working on a project where we want to capture snapshots / revisions of objects when certain operations occur. This is similar to how version control works for Reads in basecamp. Is there any stone that will automate this functionality or some kind of open source project in RoR that we can use as a reference. Greetings.

+3
source share
2 answers

act_as_versioned gem may be what you are looking for - http://github.com/technoweenie/acts_as_versioned

An example of how it works with RDoc:

page = Page.create(:title => 'hello world!')
page.version       # => 1

page.title = 'hello world'
page.save
page.version       # => 2
page.versions.size # => 2

page.revert_to(1)  # using version number
page.title         # => 'hello world!'

page.revert_to(page.versions.last) # using versioned instance
page.title         # => 'hello world'

page.versions.earliest # efficient query to find the first version
page.versions.latest   # efficient query to find the most recently created version
+4
source

. github.

+1

Source: https://habr.com/ru/post/1766216/


All Articles