Last Updated: January 17, 2017
·
8.219K
· mwalsher

Rails check if has_many changed

class Company < ActiveRecord::Base
  has_many :employees
  accepts_nested_attributes_for :employees

  def employees_changed?
    employees.select { |e| e.new_record? || e.marked_for_destruction? }.any?
  end
end

1 Response
Add your response

How about this?

employees.any? { |e| e.new_record? || e.marked_for_destruction? }

over 1 year ago ·