alexs333 alexs333 - 1 year ago 109
Ruby Question

Rails - update_column and ActiveRecord enum

I require to use

in my Rails application to prevent callbacks from being run. I have my ActiveRecord model with enum:

class Car < ActiveRecord::Base
enum state: [:not_used, :used]

In normal scenario (i.e. when I do want the callbacks to run) I can use something like that:

@car.update_attribute :state, :not_used

Is it possible to do something similar with

I am using Rails 4.2

Answer Source

update_column doesn't recognize symbols as a variant of the enum. I think that you have to Use Car.states[:not_used] instead of :not_used. Like this:

@car.update_column :state, Car.states[:not_used]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download