How to not switch on last saved version automatically? #338

Closed
kronos opened this Issue Mar 1, 2014 · 4 comments

Projects

None yet

4 participants

@kronos
kronos commented Mar 1, 2014

Assume I have a blog and posts in it is under version control with paper_trail.
After I've done a post I would like to save it (not publish) and see it in my admin's sandbox and if everything is ok I'll go ahead and publish it.

How I can implement this two features (save and publish) with paper trail? After every save the gem "activate" last version but I don't want it to do this.

Flag like "published" in post is a bad solution because, for example, some time later I will edit my post (create new version) and I do not want it to go live before I publish it.

@batter batter added the Not a bug label Mar 3, 2014
@batter
Collaborator
batter commented Mar 3, 2014

I'm not sure I fully understand what you're trying to do here. Basically, PaperTrail saves the state of a model as it was before a change is made to that model's attributes. So you could use the metadata feature to add a metadata column that marks a certain version as edited or approved or something like that. You can also create a different model like for instance Post and PostContents where the Post has an version_id field which points at the version that is currently live via a has_one association, and the PostContents has PaperTrail attached to it. That way, a user could go and choose which version they want to use after the fact or something like that. There is also the PaperTrail::Cleaner module which makes it easy to delete old versions in batches.

@LuNiPriSe

I am looking for a similar feature:

e.g. a user updates a post, but I don't want it to be public. The original post (.versions.last.reify ?) should be visible until the new version is accepted. Could it work with next_version?

@batter
Collaborator
batter commented Mar 10, 2014

If one of you has a good idea of what you think this feature would look like, then feel free to make a pull request with a proposed change. In my opinion, the easiest way to handle something like this is to have a Post and PostContents model, where the PostContents has PaperTrail attached to it, and the Post has belongs_to :post_contents and a belongs_to :version, :class_name => 'PaperTrail::Version' declared on it. Then you can either assign, or clear the version_id field depending on whether you want to use the contents in a particular version or whether you want to use the most recent changes to the PostContents model. That is how I tackled a similar objective in one application while utilizing the versioning that PaperTrail offers.

@jaredbeck
Collaborator

How about adding a published_at timestamp to your version metadata? The published record would be the one with the most recent published_at timestamp.

PaperTrail::Version.
  where(item_type: "Post").
  order(published_at: "desc").
  limit(1)

Given the lack of activity here (before this comment, 16 months) I will close this issue.

@jaredbeck jaredbeck closed this Aug 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment