xvpafa
Last Updated: January 17, 2017
·
2.747K
· 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

28510

How about this?

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

over 1 year ago ·