Class: ActiveModel::Errors
- Inherits:
-
Object
- Object
- ActiveModel::Errors
- Defined in:
- lib/active_model/errors_ext.rb
Constant Summary collapse
- @@error_class =
ActiveModel::Error
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #add(attribute, message = nil, options = {}) ⇒ Object
- #generate_message(attribute, type = :invalid, options = {}) ⇒ Object
Instance Method Details
#[](attribute) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/active_model/errors_ext.rb', line 13 def [](attribute) if errors = get(attribute.to_sym) errors else set(attribute.to_sym, AttributeErrors.new(self, attribute.to_sym)) end end |
#add(attribute, message = nil, options = {}) ⇒ Object
21 22 23 |
# File 'lib/active_model/errors_ext.rb', line 21 def add(attribute, = nil, = {}) self[attribute].add(, ) end |
#generate_message(attribute, type = :invalid, options = {}) ⇒ Object
25 26 27 28 |
# File 'lib/active_model/errors_ext.rb', line 25 def (attribute, type = :invalid, = {}) .update(:model => @base, :attribute => attribute) error_class.new(.delete(:default) || type, ) end |