Kleber S. Kleber S. - 1 year ago 87
Ruby Question

How to update a single attribute without touch updated_at attribute?

How can I achieve this?

tried to create 2 methods, called

def disable_timestamps
ActiveRecord::Base.record_timestamps = false

def enable_timestamps
ActiveRecord::Base.record_timestamps = true

and the update method itself:

def increment_pagehit
update_attribute(:pagehit, pagehit+1)

turn timestamps on and off using callbacks like:

before_update :disable_timestamps, :only => :increment_pagehit
after_update :enable_timestamps, :only => :increment_pagehit

but it's not updating anything, even the desired attribute (pagehit).

Any advice? I don't want to have to create another table just to count the pagehits.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download