Module: WellFormed::NestedAttributes
- Included in:
- NestedForm, SimpleAction, SimpleNestedForm, SimpleResource, SimpleStruct
- Defined in:
- lib/well_formed/nested_attributes.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#read_attribute_for_validation(attr) ⇒ Object
ActiveModel::Error#generate_message always calls read_attribute_for_validation to supply a :value interpolation, even when a custom :message is present.
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'lib/well_formed/nested_attributes.rb', line 5 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#read_attribute_for_validation(attr) ⇒ Object
ActiveModel::Error#generate_message always calls read_attribute_for_validation to supply a :value interpolation, even when a custom :message is present. Compound nested attribute names (e.g. :“line_items.name”) are not real methods on the form — return nil for any attribute scoped under a registered nested association to avoid a NoMethodError.
144 145 146 147 148 149 |
# File 'lib/well_formed/nested_attributes.rb', line 144 def read_attribute_for_validation(attr) attr_str = attr.to_s nested_names = self.class.registered_nested_attributes.keys.map(&:to_s) return nil if nested_names.any? { |name| attr_str.start_with?("#{name}[", "#{name}.") } super end |