作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从其他系统提供的数据库读取时遇到问题,因为我只能从中读取,并且日期时间存储在:本地时区。
与 Rails 3.2 应用程序一样,它“应该”存储在 :utc 中,就像我在这个应用程序中的所有其他表一样。
我只需要这个模型就可以在 :local 中。其余的必须在 :utc 中
我的本地时区是“UTC -04:00”
class ExternalTable < ActiveRecord::Base
establish_connection :otherdb
table_name :iseries_table <-- I have to live with it.
default_timezone = :local
puts "my default timezone is #{default_timezone}"
#lot's of defs
.....
end
> ExternalTable.inspect
«lot´s of attributes»
my default timezone is :utc <---utc!?. I have just set it to :local!?!?!?
> ExternalTable.default_timezone
:utc
> ExternalTable.default_timezone = :local
:local
> ExternalTable.default_timezone
:local <--- yeah, right. Setting it AFTER instantiated, works.
最佳答案
不应该是:
self.default_timezone = :local
class ExternalTable < ActiveRecord::Base
def self.default_timezone
:local
end
end
关于ruby-on-rails - 在单个模型上设置 default_timezone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9313900/
我从其他系统提供的数据库读取时遇到问题,因为我只能从中读取,并且日期时间存储在:本地时区。 与 Rails 3.2 应用程序一样,它“应该”存储在 :utc 中,就像我在这个应用程序中的所有其他表一样
我在日期逻辑方面遇到了一些问题,我已将其隔离到 JSON 序列化程序 Jackson。 在数据库和应用程序的调试点中,日期是正确的,所有内容都是使用默认时区编写的。但是,在连载中增加了 4 小时。我发
active_record.default_timezone 的配置似乎不像宣传的那样工作。我预计在设置后: config.active_record.default_timezone = :loc
我将我的应用时区设置为太平洋。 # application.rb: config.time_zone = 'Pacific Time (US & Canada)' 我的生产服务器时间设置为太平洋时间
我是一名优秀的程序员,十分优秀!