Reputation: 573
Currently i am upgrading my application from ruby 1.8.7 to ruby 2. I got the following issue datetime.
Ruby 1.8.7 console:
u=User.find :last
=> #<User id: 1191, login: "[email protected]", name: "Sri Lakshmi", email: "[email protected]" , created_at: "2014-01-27 12:09:04", updated_at: "2014-01-28 15:57:23">
u.updated_at="1/13/2014"
=> "1/13/2014"
u.save
=> true
Ruby 2 console:
u=User.find :last
=> #<User id: 1191, login: "[email protected]", name: "Sri Lakshmi", email: "[email protected]" , created_at: "2014-01-27 12:09:04", updated_at: "2014-01-28 15:57:23">
u.updated_at="1/13/2014"
=> "1/13/2014"
u.save
*****ArgumentError: argument out of range*****
I want the Ruby 1.8.7 datetime format in Ruby 2. I would like to keep using format I used in Ruby 1.8.7.
Upvotes: 1
Views: 209
Reputation: 26
This is not the right way to update a updated_at field. Record will be updated, but it will not be the date you actually wanted.
>> u.updated_at = "1/13/2014"
=> "1/13/2014"
>> u.save
=> true
>> u.updated_at
=> Wed, 29 Jan 2014 18:12:51 UTC +00:00
Upvotes: 0
Reputation: 26
ok. Now I understand your requirement. In that case, you can change the default format through out the application. Please follow the steps mentioned in the link,
http://blog.nicoschuele.com/posts/cheatsheet-to-set-app-wide-date-and-time-formats-in-rails
Upvotes: 1