2015-09-07 17:41:50 -04:00
|
|
|
* Validate multiple contexts on `valid?` and `invalid?` at once.
|
|
|
|
|
|
|
|
Example:
|
2015-09-08 14:37:17 -04:00
|
|
|
|
2015-09-07 17:41:50 -04:00
|
|
|
class Person
|
|
|
|
include ActiveModel::Validations
|
2015-09-08 14:37:17 -04:00
|
|
|
|
2015-09-07 17:41:50 -04:00
|
|
|
attr_reader :name, :title
|
|
|
|
validates_presence_of :name, on: :create
|
|
|
|
validates_presence_of :title, on: :update
|
|
|
|
end
|
2015-09-08 14:37:17 -04:00
|
|
|
|
2015-09-07 17:41:50 -04:00
|
|
|
person = Person.new
|
2015-09-08 14:37:17 -04:00
|
|
|
person.valid?([:create, :update]) # => false
|
2015-09-07 17:41:50 -04:00
|
|
|
person.errors.messages # => {:name=>["can't be blank"], :title=>["can't be blank"]}
|
|
|
|
|
|
|
|
*Dmitry Polushkin*
|
|
|
|
|
2015-09-01 01:42:43 -04:00
|
|
|
* Add case_sensitive option for confirmation validator in models.
|
2014-08-06 10:41:36 -04:00
|
|
|
|
2015-09-01 01:42:43 -04:00
|
|
|
*Akshat Sharma*
|
2014-08-06 10:41:36 -04:00
|
|
|
|
2015-01-17 02:12:32 -05:00
|
|
|
* Ensure `method_missing` is called for methods passed to
|
|
|
|
`ActiveModel::Serialization#serializable_hash` that don't exist.
|
|
|
|
|
|
|
|
*Jay Elaraj*
|
|
|
|
|
2015-05-05 14:11:35 -04:00
|
|
|
* Remove `ActiveModel::Serializers::Xml` from core.
|
|
|
|
|
|
|
|
*Zachary Scott*
|
|
|
|
|
2015-04-21 12:56:43 -04:00
|
|
|
* Add `ActiveModel::Dirty#[attr_name]_previously_changed?` and
|
|
|
|
`ActiveModel::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*
|
|
|
|
|
2015-03-29 18:34:01 -04:00
|
|
|
* Deprecate the `:tokenizer` option for `validates_length_of`, in favor of
|
|
|
|
plain Ruby.
|
|
|
|
|
|
|
|
*Sean Griffin*
|
|
|
|
|
2015-02-18 17:04:16 -05:00
|
|
|
* Deprecate `ActiveModel::Errors#add_on_empty` and `ActiveModel::Errors#add_on_blank`
|
|
|
|
with no replacement.
|
|
|
|
|
|
|
|
*Wojciech Wnętrzak*
|
|
|
|
|
2015-01-21 16:47:39 -05:00
|
|
|
* Deprecate `ActiveModel::Errors#get`, `ActiveModel::Errors#set` and
|
2015-05-20 13:22:18 -04:00
|
|
|
`ActiveModel::Errors#[]=` methods that have inconsistent behavior.
|
2015-01-21 16:47:39 -05:00
|
|
|
|
|
|
|
*Wojciech Wnętrzak*
|
|
|
|
|
2015-04-22 08:44:30 -04:00
|
|
|
* Allow symbol as values for `tokenize` of `LengthValidator`.
|
2014-08-03 01:50:09 -04:00
|
|
|
|
|
|
|
*Kensuke Naito*
|
|
|
|
|
2015-01-23 17:36:43 -05:00
|
|
|
* Assigning an unknown attribute key to an `ActiveModel` instance during initialization
|
|
|
|
will now raise `ActiveModel::AttributeAssignment::UnknownAttributeError` instead of
|
2015-02-23 10:54:40 -05:00
|
|
|
`NoMethodError`.
|
2015-01-23 17:36:43 -05:00
|
|
|
|
2015-01-31 05:54:00 -05:00
|
|
|
Example:
|
|
|
|
|
|
|
|
User.new(foo: 'some value')
|
|
|
|
# => ActiveModel::AttributeAssignment::UnknownAttributeError: unknown attribute 'foo' for User.
|
2015-01-23 17:36:43 -05:00
|
|
|
|
|
|
|
*Eugene Gilburg*
|
|
|
|
|
2015-01-23 06:57:34 -05:00
|
|
|
* Extracted `ActiveRecord::AttributeAssignment` to `ActiveModel::AttributeAssignment`
|
2015-01-31 05:54:00 -05:00
|
|
|
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")
|
2015-04-05 09:55:18 -04:00
|
|
|
cat.name # => 'Gorby'
|
|
|
|
cat.status # => 'yawning'
|
2015-01-31 05:54:00 -05:00
|
|
|
cat.assign_attributes(status: "sleeping")
|
2015-04-05 09:55:18 -04:00
|
|
|
cat.name # => 'Gorby'
|
|
|
|
cat.status # => 'sleeping'
|
2015-01-23 06:57:34 -05:00
|
|
|
|
|
|
|
*Bogdan Gusiev*
|
|
|
|
|
2015-01-04 03:18:03 -05:00
|
|
|
* Add `ActiveModel::Errors#details`
|
|
|
|
|
|
|
|
To be able to return type of used validator, one can now call `details`
|
2015-01-31 05:54:00 -05:00
|
|
|
on errors instance.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
class User < ActiveRecord::Base
|
|
|
|
validates :name, presence: true
|
|
|
|
end
|
|
|
|
|
|
|
|
user = User.new; user.valid?; user.errors.details
|
|
|
|
=> {name: [{error: :blank}]}
|
2015-01-04 03:18:03 -05:00
|
|
|
|
|
|
|
*Wojciech Wnętrzak*
|
|
|
|
|
2015-01-10 11:35:58 -05:00
|
|
|
* Change validates_acceptance_of to accept true by default.
|
|
|
|
|
|
|
|
The default for validates_acceptance_of is now "1" and true.
|
2015-01-04 03:18:03 -05:00
|
|
|
In the past, only "1" was the default and you were required to add
|
2015-01-10 11:35:58 -05:00
|
|
|
accept: true.
|
|
|
|
|
2015-01-03 16:20:30 -05:00
|
|
|
* Remove deprecated `ActiveModel::Dirty#reset_#{attribute}` and
|
|
|
|
`ActiveModel::Dirty#reset_changes`.
|
|
|
|
|
|
|
|
*Rafael Mendonça França*
|
|
|
|
|
2014-12-24 03:58:19 -05:00
|
|
|
* 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, returning `false` in an ActiveModel or ActiveModel::Validations
|
|
|
|
`before_` callback had the side effect of halting the callback chain.
|
|
|
|
This is not recommended anymore and, depending on the value of the
|
|
|
|
`config.active_support.halt_callback_chains_on_return_false` option, will
|
|
|
|
either not work at all or display a deprecation warning.
|
2014-12-08 09:35:25 -05:00
|
|
|
|
|
|
|
|
2014-11-28 12:00:06 -05:00
|
|
|
Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activemodel/CHANGELOG.md) for previous changes.
|