Skip to content
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

Support Rails 5's saved_changes #106

Closed
brianstorti opened this issue Oct 9, 2017 · 4 comments
Closed

Support Rails 5's saved_changes #106

brianstorti opened this issue Oct 9, 2017 · 4 comments

Comments

@brianstorti
Copy link

Rails 5 introduced the saved_changes method to the Dirty module, but it seems like Mobility still doesn't support that:

class Post
  include Mobility
  translates :translated_attribute, dirty: true
end

post = Post.first
post.translated_attribute = "test"
post.not_a_translated_attribute = "test"

post.changes 
# => { "translated_attribute" => ["", "test"], "not_a_translated_attribute" => ["", test] }

post.save!

post.saved_changed 
# => { "not_a_translated_attribute" => ["", "test"] }

It would be great if saved_changes also returned the translated attributes.

Thank you.

@shioyama
Copy link
Owner

Thanks, sounds like a good idea. I'll try adding it in the next round of changes for the release of 0.3.0.

@shioyama
Copy link
Owner

shioyama commented Nov 27, 2017

Actually, there are more methods: saved_change_to_foo?, saved_change_to_foo, foo_before_last_save, will_save_change_to_foo?, foo_change_to_be_saved, and foo_in_database.

@shioyama
Copy link
Owner

@brianstorti saved_changes as well as other AR-specific dirty methods added in AR 5.1 have been added to the master branch of Mobility. Give them a spin 😄

@brianstorti
Copy link
Author

@shioyama Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants