No commit activity in last 3 years
No release in over 3 years
Monkey patch to index nested errors for ActiveRecord 4
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

ActiveRecord Nested Error Indexer

In Rails 5, we have the option index_errors: true to output the nested item index for errors like this:

class Order < ApplicationRecord
  has_many :items, index_errors: true

  accepts_nested_attributes_for :items
end

order = Order.create(items_attributes: [{ price: 1 }, { price: -1 }])
order.errors # #<ActiveModel::Errors... @messages={:*"items[1].price"*: ["must be greater than 0"]}>

BUT IT DOESN'T WORK FOR RAILS 4, so... let's monkey patch it :)

Installation

Include to your Gemfile

gem 'active_record-nested_error_indexer'

Maintainer

Dhyego Fernando