This commit is a backport of b3dfd7d
.
We now use default procs inside of the errors object, which gets
included by default when marshaling anything that includes
`ActiveModel::Validations`. This means that Active Record objects cannot
be marshalled. We strip and apply the default proc ourselves. This will
ensure the objects are YAML serializable as well, since YAML falls back
to marshal implementations now. This is less important, however, as the
errors aren't included when dumping Active Record objects.
Fixes #25165
4.4 KiB
-
Ensure that instances of
ActiveModel::Errors
can be marshalled. Fixes #25165.Sean Griffin
Rails 5.0.0.rc1 (May 06, 2016)
- No changes.
Rails 5.0.0.beta4 (April 27, 2016)
-
Allow passing record being validated to the message proc to generate customized error messages for that object using I18n helper.
Prathamesh Sonpatki
Rails 5.0.0.beta3 (February 24, 2016)
- No changes.
Rails 5.0.0.beta2 (February 01, 2016)
- No changes.
Rails 5.0.0.beta1 (December 18, 2015)
-
Validate multiple contexts on
valid?
andinvalid?
at once.Example:
class Person include ActiveModel::Validations attr_reader :name, :title validates_presence_of :name, on: :create validates_presence_of :title, on: :update end person = Person.new person.valid?([:create, :update]) # => false person.errors.messages # => {:name=>["can't be blank"], :title=>["can't be blank"]}
Dmitry Polushkin
-
Add case_sensitive option for confirmation validator in models.
Akshat Sharma
-
Ensure
method_missing
is called for methods passed toActiveModel::Serialization#serializable_hash
that don't exist.Jay Elaraj
-
Remove
ActiveModel::Serializers::Xml
from core.Zachary Scott
-
Add
ActiveModel::Dirty#[attr_name]_previously_changed?
andActiveModel::Dirty#[attr_name]_previous_change
to improve access to recorded changes after the model has been saved.It makes the dirty-attributes query methods consistent before and after saving.
Fernando Tapia Rico
-
Deprecate the
:tokenizer
option forvalidates_length_of
, in favor of plain Ruby.Sean Griffin
-
Deprecate
ActiveModel::Errors#add_on_empty
andActiveModel::Errors#add_on_blank
with no replacement.Wojciech Wnętrzak
-
Deprecate
ActiveModel::Errors#get
,ActiveModel::Errors#set
andActiveModel::Errors#[]=
methods that have inconsistent behavior.Wojciech Wnętrzak
-
Allow symbol as values for
tokenize
ofLengthValidator
.Kensuke Naito
-
Assigning an unknown attribute key to an
ActiveModel
instance during initialization will now raiseActiveModel::AttributeAssignment::UnknownAttributeError
instead ofNoMethodError
.Example:
User.new(foo: 'some value') # => ActiveModel::AttributeAssignment::UnknownAttributeError: unknown attribute 'foo' for User.
Eugene Gilburg
-
Extracted
ActiveRecord::AttributeAssignment
toActiveModel::AttributeAssignment
allowing to use it for any object as an includable module.Example:
class Cat include ActiveModel::AttributeAssignment attr_accessor :name, :status end cat = Cat.new cat.assign_attributes(name: "Gorby", status: "yawning") cat.name # => 'Gorby' cat.status # => 'yawning' cat.assign_attributes(status: "sleeping") cat.name # => 'Gorby' cat.status # => 'sleeping'
Bogdan Gusiev
-
Add
ActiveModel::Errors#details
To be able to return type of used validator, one can now call
details
on errors instance.Example:
class User < ActiveRecord::Base validates :name, presence: true end user = User.new; user.valid?; user.errors.details => {name: [{error: :blank}]}
Wojciech Wnętrzak
-
Change
validates_acceptance_of
to accepttrue
by default besides'1'
.The default for
validates_acceptance_of
is now'1'
andtrue
. In the past, only"1"
was the default and you were required to passaccept: true
separately.mokhan
-
Remove deprecated
ActiveModel::Dirty#reset_#{attribute}
andActiveModel::Dirty#reset_changes
.Rafael Mendonça França
-
Change the way in which callback chains can be halted.
The preferred method to halt a callback chain from now on is to explicitly
throw(:abort)
. In the past, returningfalse
in an Active Modelbefore_
callback had the side effect of halting the callback chain. This is not recommended anymore and, depending on the value of theActiveSupport.halt_callback_chains_on_return_false
option, will either not work at all or display a deprecation warning.claudiob
Please check 4-2-stable for previous changes.