I have following model -
class Project < ActiveRecord::Base
enum commitment: {
more_than_30hrs_week: 'More than 30hrs/week',
less_than_30hrs_week: 'Less than 30hrs/week',
dont_know: 'Dont know'
}
enum status: [:open, :closed, :archived]
validates :commitment, :status :presence => true
end
When I try to update project object like the following -
@project.update!(project_params)
where -
@project = #<Project:0x007fde227059d8
id: 5,
commitment: "less than 30hrs/week",
status: 2 >
project_params = {"status"=>"archived"}
It throws me following error -
ActiveRecord::RecordInvalid: Validation failed: Commitment can't be blank
I fail to understand why is it throwing this error as commitment value already exists and I am not passing in the attributes to update.
Doing the following works but I do not want it this way as I want to update multiple attributes -
@project.update_attribute(:status, 'archived')
Can someone please explain, how can I achieve this?