mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
21e448b5a5
`has_many` can now take `index_errors: true` as an option. When this is enabled, errors for nested models will be returned alongside an index, as opposed to just the nested model name. This option can also be enabled (or disabled) globally through `ActiveRecord::Base.index_nested_attribute_errors` E.X. ```ruby class Guitar < ActiveRecord::Base has_many :tuning_pegs accepts_nested_attributes_for :tuning_pegs end class TuningPeg < ActiveRecord::Base belongs_to :guitar validates_numericality_of :pitch end ``` - Old style - `guitar.errors["tuning_pegs.pitch"] = ["is not a number"]` - New style (if defined globally, or set in has_many_relationship) - `guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]` [Michael Probber, Terence Sun]
4 lines
97 B
Ruby
4 lines
97 B
Ruby
class TuningPeg < ActiveRecord::Base
|
|
belongs_to :guitar
|
|
validates_numericality_of :pitch
|
|
end
|