ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

Limit checks are improperly failing when removing and then adding fields #316

Open robertwbradford opened 10 years ago

robertwbradford commented 10 years ago

Let's say you have put limits in place with either of the following:

class Order < ActiveRecord::Base
  accepts_nested_attributes_for :line_items, limit: 3, allow_destroy: true
  # OR
  validates :line_items, length: { maximum: 3 }
end

Now let's say you go to edit an Order that already has 3 line items. If you remove one of the items, click the add link to add another item, and then submit the form, the validation will fail saying there are too many items. (Or if using the :limit option for accepts_nested_attributes_for you get ActiveRecord::NestedAttributes::TooManyRecords.