I have a table with Time
data type column, which stores times from users (via f.time_select
form helper). It works fine when I input time through the form, but I can't create a time object from rails irb console with .create
or .new
. The message is:
irb(main):003:0> Sleep.create(hours: "1970-01-01 06:15:00") DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This still causes
String
s to be parsed as if they were inTime.zone
, andTime
s to be converted toTime.zone
.To keep the old behavior, you must add the following to your initializer:
config.active_record.time_zone_aware_types = [:datetime]
To silence this deprecation warning, add the following:
config.active_record.time_zone_aware_types = [:datetime, :time] (called from irb_binding at (irb):3) DEPRECATION WARNING: Time columns
will become time zone aware in Rails 5.1. This still causes
String
s to be parsed as if they were inTime.zone
, andTime
s to be converted toTime.zone
.To keep the old behavior, you must add the following to your initializer:
config.active_record.time_zone_aware_types = [:datetime]
To silence this deprecation warning, add the following:
config.active_record.time_zone_aware_types = [:datetime, :time]
I was trying to add each of these lines to the config/application.rb
under class Application < Rails::Application
and then try different syntaxis combinations to create time through irb, like Sleep.create(hours: "1970-01-01", "06:20:00")
but nothing worked.
I'm also getting results like this:
Loading development environment (Rails 5.0.2)
irb(main):001:0> irb(main):003:0> Sleep.create(hours: "1970-01-01 06:15:00")
SyntaxError: (irb):1: syntax error, unexpected ':', expecting end-of-input
irb(main):003:0> Sleep.create(hours: "19
or
Sleep.create(hours: "1970-01-01", "06:15:00")
irb(main):002:0> Sleep.create(hours: "1970-01-01", "06:15:00")
SyntaxError: (irb):2: syntax error, unexpected ')', expecting =>
urs: "1970-01-01", "06:15:00")
What am I doing wrong and how can I create some particular time from irb?