Update Rails model without touching timestamp temporary -


i have tweet model. want update model attributes without updating timestamp.

i've read/tried links , didn't work me:

i tried override activerecord::base mentioned in second link, creating new file active_record_base_patches.rb inside lib directory. but, engine said method not found in tweet model.

so, tried move update_record_without_timestamping tweet model. method found timestamp updated.

is there simple method disable timestamp in rails while? laravel 4 has this: https://stackoverflow.com/a/18906324/3427434.

ps: use ruby on rails 4.2.3 on ruby 2.2.0.

you create concern in model/concern, named model_timestamp.rb

require 'active_support/concern'  module modeltimestamp   extend activesupport::concern    module classmethods     def without_timestamps       old = activerecord::base.record_timestamps       activerecord::base.record_timestamps = false       begin          yield        ensure         activerecord::base.record_timestamps = old       end     end   end end 

then in model tweet add include modeltimestamp

class tweet < activerecord::base   include modeltimestamp    ... end 

then want update attributes without timestamps change use

tweet = tweet.last tweet.without_timestamps   tweet.update(attributes) end 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -