No changes
No changes
No changes
No changes
No changes
No changes
No changes
No changes
No changes
No changes
-
#to_paramreturnsnilif#to_keyreturnsnil. Fixes #11399.Yves Senn
No changes
No changes
-
Fix
has_secure_passwordto honor bcrypt-ruby's cost attribute.T.J. Schuck
-
inclusion/exclusionvalidations with ranges will only use the fasterRange#coverfor numerical ranges, and the more accurateRange#include?for non-numerical ones.Fixes range validations like
:a..:fthat used to pass with values like:be.Fixes #10593.
Charles Bergeron
-
Fix regression in has_secure_password. When a password is set, but a confirmation is an empty string, it would incorrectly save.
Steve Klabnik and Phillip Calvin
-
Add
ActiveModel::Errors#full_messages_for, to return all the error messages for a given attribute.Example:
class Person include ActiveModel::Validations attr_reader :name, :email validates_presence_of :name, :email end person = Person.new person.valid? # => false person.errors.full_messages_for(:name) # => ["Name can't be blank"]Volodymyr Shatsky
-
Added a method so that validations can be easily cleared on a model. For example:
class Person include ActiveModel::Validations validates_uniqueness_of :first_name validate :cannot_be_robot def cannot_be_robot errors.add(:base, 'A person cannot be a robot') if person_is_robot end endNow, if someone runs
Person.clear_validators!, then the following occurs:Person.validators # => [] Person._validate_callbacks.empty? # => trueJohn Wang
-
has_secure_passworddoes not fail the confirmation validation when assigning empty String topasswordandpassword_confirmation. Fixes #9535.Example:
# Given User has_secure_password. @user.password = "" @user.password_confirmation = "" @user.valid?(:update) # used to be falseYves Senn
-
validates_confirmation_ofdoes not override writer methods for the confirmation attribute if no reader is defined.Example:
class Blog def title=(new_title) @title = new_title.downcase end # previously this would override the setter above. validates_confirmation_of :title endYves Senn
-
Add
ActiveModel::Validations::AbsenceValidator, a validator to check the absence of attributes.class Person include ActiveModel::Validations attr_accessor :first_name validates_absence_of :first_name end person = Person.new person.first_name = "John" person.valid? # => false person.errors.messages # => {:first_name=>["must be blank"]}Roberto Vasquez Angel
-
[attribute]_changed?now returnsfalseafter a call toreset_[attribute]!.Renato Mascarenhas
-
Observers was extracted from Active Model as
rails-observersgem.Rafael Mendonça França
-
Specify type of singular association during serialization.
Steve Klabnik
-
Fixed length validator to correctly handle
nil. Fixes #7180.Michal Zima
-
Removed dispensable
requirestatements. Make sure to requireactive_modelbefore requiring individual parts of the framework.Yves Senn
-
Use BCrypt's
MIN_COSTin the test environment for speedier tests when usinghas_secure_password.Brian Cardarella + Jeremy Kemper + Trevor Turk
-
Add
ActiveModel::ForbiddenAttributesProtection, a simple module to protect attributes from mass assignment when non-permitted attributes are passed.DHH + Guillermo Iguaran
-
ActiveModel::MassAssignmentSecurityhas been extracted from Active Model and theprotected_attributesgem should be added to Gemfile in order to useattr_accessibleandattr_protectedmacros in your models.Guillermo Iguaran
-
Due to a change in builder,
niland empty strings now generate closed tags, so instead of this:<pseudonyms nil=\"true\"></pseudonyms>it generates this:
<pseudonyms nil=\"true\"/>Carlos Antonio da Silva
-
Inclusion/exclusion validators accept a method name passed as a symbol to the
:inoption.This allows to use dynamic inclusion/exclusion values using methods, besides the current lambda/proc support.
Gabriel Sobrinho
-
ActiveModel::Validation#validatesability to pass custom exception to the:strictoption.Bogdan Gusiev
-
Changed
ActiveModel::Serializers::Xml::Serializer#add_associationsto by default propagate:skip_types, :dasherize, :camelizekeys to included associations. It can be overridden on each association by explicitly specifying the option on one or more associationsAnthony Alberto
-
Changed
ActiveModel::Serializers::JSON.include_root_in_jsondefault value to false. Now, AM Serializers and AR objects have the same default behaviour. Fixes #6578.class User < ActiveRecord::Base; end class Person include ActiveModel::Model include ActiveModel::AttributeMethods include ActiveModel::Serializers::JSON attr_accessor :name, :age def attributes instance_values end end user.as_json => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true} # root is not included person.as_json => {"name"=>"Francesco", "age"=>22} # root is not includedFrancesco Rodriguez
-
Passing false hash values to
validateswill no longer enable the corresponding validators.Steve Purcell
-
ConfirmationValidatorerror messages will attach to:#{attribute}_confirmationinstead ofattribute.Brian Cardarella
-
Added
ActiveModel::Model, a mixin to make Ruby objects work with AP out of box.Guillermo Iguaran
-
AM::Errors#to_json: support:full_messagesparameter.Bogdan Gusiev
-
Trim down Active Model API by removing
valid?anderrors.full_messages.José Valim
-
When
^or$are used in the regular expression provided tovalidates_format_ofand the:multilineoption is not set to true, an exception will be raised. This is to prevent security vulnerabilities when usingvalidates_format_of. The problem is described in detail in the Rails security guide.Jan Berdajs + Egor Homakov
Please check 3-2-stable for previous changes.