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
Written by Mike Walsh
Related protips
1 Response
How about this?
employees.any? { |e| e.new_record? || e.marked_for_destruction? }
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#