Why none of the validations work in update mode when using the below
model
relation and nested forms:
#timesheet.rb
class Timesheet < ActiveRecord::Base
has_many :activities, dependent: :destroy
has_many :time_entries, through: :activities
validates_associated :activities, length: { minimum: 1 }
validates_presence_of :activities
…
end
#activity.rb
class Activity < ActiveRecord::Base
class Activity < ActiveRecord::Base
attr_accessible :task_id, :timesheet_id, :time_entries_attributes
validates :task_id, presence: true
belongs_to :timesheet
belongs_to :task
has_many :time_entries, order: :workdate, dependent: :destroy
end
If when updating a timesheet I remove an activity, the timesheet will be
updated with no problems instead of raising validation error on
activity.
Any idea? Thank you.