-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to track Mobility translated attributes and Action Text? #45
Comments
Here is a demo for Action Text: class Page < ApplicationRecord
include ActiveSnapshot
has_rich_text :body
has_snapshot_children do
instance = self.class.includes(:rich_text_body).find(id)
{ rich_text_body: instance.rich_text_body }
end
end I manage to create the snapshot but again not to restore it. |
Demo with translated Action Text: class Page < ApplicationRecord
extend Mobility
include ActiveSnapshot
translates :body, backend: :action_text # Using https://github.com/sedubois/mobility-actiontext/
has_snapshot_children do
instance = self.class.includes(:rich_text_body).find(id)
{ rich_text_body: instance.rich_text_body }
end
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this gem! I am evaluating it to track attributes which PaperTrail does not track properly.
Using Mobility, with the default installation (key-value backend), how do I track translated attributes (without having conflicts between different locales and in a way where records can be restored)?
I tried this:
If I have e.g. 2 locales and ensure that the page has a
title
value in each of those 2 locales, then callingsnapshot = page.create_snapshot!
successfully creates 3 snapshot items: one for the main record and one for each of the associated string_translations. This is good news because I hadn't managed to do this so far with Paper Trail or Audited (but I would be happy to be proven wrong.)However when calling
snapshot.restore!
I get the errorPG::UniqueViolation: ERROR: duplicate key value violates unique constraint "pages_pkey"
.Questions:
title
attribute instead of referring tostring_translations
which is meant to be an implementation detail? As the name suggests, Mobility is supposed to allow flexibly using different types of backends and the association namestring_translations
is only applicable to its key-value backend.has_snapshot_children
tohas_associated_snapshots
or similar?Finally, I need to combine all 3 aspects: snapshots for Action Text rich texts which are translated. I manage to translate Action Text rich texts using this gem I built. I could try combining it with this gem when I have more clarifications on the questions above.
The text was updated successfully, but these errors were encountered: