For example I’ve changed value of Post’s object and it didn’t pass validation:
my_post = Post.last
my_post.name
# => "foobar"
my_post.name = "something wrong"
my_post.save
# => (0.1ms) begin transaction
# => (0.0ms) rollback transaction
# => false
my_post.name
# => "something wrong"
The actual value is still “foobar”, but how can I return it now, without creating a new object?
changesreturns a hash of the changes made to a model object:This can also be accessed via the dynamically-generated method:
in your case you should do
More on this is available in the documentation for
ActiveModel::Dirty.