@@ -115,36 +115,6 @@ def include?(attribute)
115
115
alias :has_key? :include?
116
116
alias :key? :include?
117
117
118
- # Get messages for +key+.
119
- #
120
- # person.errors.messages # => {:name=>["cannot be nil"]}
121
- # person.errors.get(:name) # => ["cannot be nil"]
122
- # person.errors.get(:age) # => []
123
- def get ( key )
124
- ActiveSupport ::Deprecation . warn ( <<-MESSAGE . squish )
125
- ActiveModel::Errors#get is deprecated and will be removed in Rails 5.1.
126
-
127
- To achieve the same use model.errors[:#{ key } ].
128
- MESSAGE
129
-
130
- messages [ key ]
131
- end
132
-
133
- # Set messages for +key+ to +value+.
134
- #
135
- # person.errors[:name] # => ["cannot be nil"]
136
- # person.errors.set(:name, ["can't be nil"])
137
- # person.errors[:name] # => ["can't be nil"]
138
- def set ( key , value )
139
- ActiveSupport ::Deprecation . warn ( <<-MESSAGE . squish )
140
- ActiveModel::Errors#set is deprecated and will be removed in Rails 5.1.
141
-
142
- Use model.errors.add(:#{ key } , #{ value . inspect } ) instead.
143
- MESSAGE
144
-
145
- messages [ key ] = value
146
- end
147
-
148
118
# Delete messages for +key+. Returns the deleted messages.
149
119
#
150
120
# person.errors[:name] # => ["cannot be nil"]
@@ -173,20 +143,6 @@ def [](attribute)
173
143
messages [ attribute . to_sym ]
174
144
end
175
145
176
- # Adds to the supplied attribute the supplied error message.
177
- #
178
- # person.errors[:name] = "must be set"
179
- # person.errors[:name] # => ['must be set']
180
- def []=( attribute , error )
181
- ActiveSupport ::Deprecation . warn ( <<-MESSAGE . squish )
182
- ActiveModel::Errors#[]= is deprecated and will be removed in Rails 5.1.
183
-
184
- Use model.errors.add(:#{ attribute } , #{ error . inspect } ) instead.
185
- MESSAGE
186
-
187
- messages [ attribute . to_sym ] << error
188
- end
189
-
190
146
# Iterates through each error key, value pair in the error messages hash.
191
147
# Yields the attribute and the error for that attribute. If the attribute
192
148
# has more than one error message, yields once for each error message.
@@ -338,49 +294,6 @@ def add(attribute, message = :invalid, options = {})
338
294
messages [ attribute . to_sym ] << message
339
295
end
340
296
341
- # Will add an error message to each of the attributes in +attributes+
342
- # that is empty.
343
- #
344
- # person.errors.add_on_empty(:name)
345
- # person.errors.messages
346
- # # => {:name=>["can't be empty"]}
347
- def add_on_empty ( attributes , options = { } )
348
- ActiveSupport ::Deprecation . warn ( <<-MESSAGE . squish )
349
- ActiveModel::Errors#add_on_empty is deprecated and will be removed in Rails 5.1.
350
-
351
- To achieve the same use:
352
-
353
- errors.add(attribute, :empty, options) if value.nil? || value.empty?
354
- MESSAGE
355
-
356
- Array ( attributes ) . each do |attribute |
357
- value = @base . send ( :read_attribute_for_validation , attribute )
358
- is_empty = value . respond_to? ( :empty? ) ? value . empty? : false
359
- add ( attribute , :empty , options ) if value . nil? || is_empty
360
- end
361
- end
362
-
363
- # Will add an error message to each of the attributes in +attributes+ that
364
- # is blank (using Object#blank?).
365
- #
366
- # person.errors.add_on_blank(:name)
367
- # person.errors.messages
368
- # # => {:name=>["can't be blank"]}
369
- def add_on_blank ( attributes , options = { } )
370
- ActiveSupport ::Deprecation . warn ( <<-MESSAGE . squish )
371
- ActiveModel::Errors#add_on_blank is deprecated and will be removed in Rails 5.1.
372
-
373
- To achieve the same use:
374
-
375
- errors.add(attribute, :blank, options) if value.blank?
376
- MESSAGE
377
-
378
- Array ( attributes ) . each do |attribute |
379
- value = @base . send ( :read_attribute_for_validation , attribute )
380
- add ( attribute , :blank , options ) if value . blank?
381
- end
382
- end
383
-
384
297
# Returns +true+ if an error on the attribute with the given message is
385
298
# present, or +false+ otherwise. +message+ is treated the same as for +add+.
386
299
#
0 commit comments