gpt4 book ai didi

ruby-on-rails - 更改 Heroku(ruby on rails) 服务器的日期和时间

转载 作者:行者123 更新时间:2023-12-05 00:16:15 25 4
gpt4 key购买 nike

我有 ruby​​ on rails 应用程序,它托管在 Heroku 上。出于测试目的,我必须更改服务器的日期和时间。
或者手动将其设置为特定日期..?
有什么办法可以做到这一点..?
使用控制台或任何东西。?

最佳答案

我通过 Timecop 实现了这一点gem 使用 around_action更改我的登台环境中的时间。

module TimeTravelFilters
extend ActiveSupport::Concern

included do
if Time::Clock.travel_ok?
around_action :time_travel_for_request
end
end

def time_travel_for_request
time_travel
yield
time_travel_return
end

def time_travel
if Time::Clock.fake_time
Timecop.travel Time::Clock.fake_time
else
Timecop.return
end
end

def time_travel_return
Timecop.return
end
end
Time::Clock是我自己的类(class),跟踪假时间。

我有一个单独的 TimeController这让我可以更改服务器上的时间。
class TimeController < ApplicationController
before_action :require_admin!

def index
end

def update
@clock.update_attributes params[:time_clock]
redirect_to time_index_path
end

def destroy
@clock.reset
redirect_to time_index_path
end
end

关于ruby-on-rails - 更改 Heroku(ruby on rails) 服务器的日期和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42435976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com