dAr*_*GhT 5 ruby-on-rails heroku heroku-toolbelt
我在Heroku上托管的rails应用程序上有ruby.出于测试目的,我必须更改服务器的日期和时间.或者手动将其设置为特定日期..?我有什么方法可以做到这一点......?使用控制台或任何东西.?
我通过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
Run Code Online (Sandbox Code Playgroud)
Time::Clock是我自己的课程,它跟踪假时间。
我有一个单独的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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1316 次 |
| 最近记录: |