Comments (5)
Thanks for the details! Glad you found a fix. For reference, Mobility doesn't support compatibility with other gems, that's something you need to figure out yourself (which it seems like you have).
from mobility.
Found another important aspect, after the update the object has a different ID than the one it had before saving the record:
Before @song.update
:
#<Mobility::Backends::ActionText::RichTextTranslation:0x00000001192de460
id: nil,
name: "description",
body: nil,
record_type: "Song",
record_id: 4,
created_at: nil,
updated_at: nil,
locale: "en">
After @song.update
:
#<Mobility::Backends::ActionText::RichTextTranslation:0x000000011a3e6168
id: nil,
name: "description",
body: nil,
record_type: "Song",
record_id: 4,
created_at: nil,
updated_at: nil,
locale: "en">
Could it be that this is what ends up adding the value to the @song.previous_changes
hash?
from mobility.
I have also opened an issue at mobility-actiontext
: sedubois/mobility-actiontext#37
I noticed that comparing the previous Mobility::Backends::ActionText
body
value with the new one can be used to determine if something is changed.
I'm trying to build some logic to filter out attributes that use Mobility::Backends::ActionText
out of previous_changes
if no changes were made to them but it might be a hacky way. I'll share it here if I get it working!
from mobility.
For now, I've solved it like this, sharing in case it helps anyone in the future:
def record_changed?(previous_record, current_record, params)
record_changes = current_record.previous_changes
mobility_action_text = "Mobility::Backends::ActionText::RichTextTranslation"
# Loop through each array of changes:
record_changes&.each do |key, value|
# Previous value is used to compare the class name but it can't be compared with changed_value because they're both storing updated values.
previous_value = value[0]
changed_value = value[1]
# Check if the items for each changes array are part of Mobility Action Text
if previous_value&.class&.name == mobility_action_text
# Compares a duplicate of the original object because previous_value and changed value cannot be trusted.
# Removes key entirely if the value is still the same:
if previous_record&.public_send(key)&.to_plain_text == current_record&.public_send(key)&.to_plain_text
record_changes.delete(key)
end
end
end
# If both content and description were not changed, then remove update from the hash.
if record_changes.size == 1 && record_changes["updated_at"]&.present?
record_changes.delete("updated_at")
end
# Whether or not the record has changed.
return record_changes.empty? ? false : true
end
Please feel free to close if this is out of scope of the library, thanks a lot!
from mobility.
Thanks @shioyama! It's reassuring to read that extending is a good way of doing things. That's correct, I have adapted it for now and it seems to work fine.
from mobility.
Related Issues (20)
- Issue with backend extention HOT 1
- reader & locale_accessors won't return correct translation, but backend_reader does HOT 5
- Destruction of DB records with linked translation records fails (with a strange SQL query) HOT 2
- Model attribute defined fallback HOT 2
- Error when ordering and selecting distinct on translated resource HOT 2
- Cache issue with JSONb (+locale_accessors) & ActiveRecord HOT 2
- Using a query method block does not automatically scope to i18n HOT 1
- Translated inputs are empty after failed form validation in a specific setup HOT 1
- Automatic ActionText `rich_text` detection failing when operating on locale-dependent mobility field HOT 1
- Any accepted way to store images working with active storage ? HOT 1
- Unique Validation didn't work with locale_accessors on every locales HOT 1
- Not compatible with FastGettext - request for string available locale support HOT 2
- Error when installing on Vitess MySQL db HOT 4
- The presence plugin doesn't work as expected HOT 1
- Destruction of record+translations fails, when model IDs are of the type "varchar(36)" (a UUID string) HOT 3
- accessor super method doesn't work with arguments like class.value(locale: :de) HOT 1
- ordering by specific locale HOT 2
- Add type checking plugin reference HOT 3
- eager_load and pluck builds the wrong query HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobility.