gpt4 book ai didi

ruby-on-rails-3 - Rails 3 无法开始 beginning_of_week

转载 作者:行者123 更新时间:2023-12-02 08:53:28 24 4
gpt4 key购买 nike

有一个 publish_on 日期时间字段。

只是想从 publish_on 开始到 beginning_of_week。

试过 helper

def start_week(publish_on)
DateTime.parse(publish_on).beginning_of_week
end

在 View 中<%= start_week(@survey.publish_on) %>

在我的模型中试过

def set_start_week
publish_on.beginning_of_week
end

见鬼,连这个 helper 都试过了

def this_should_work
DateTime.now.beginning_of_week
end

但在我看来,一切都返回无效日期。它在 irb 中有效,为什么在我看来不行?

编辑

module SurveysHelper
require 'date'
require 'time'

def this_should_work
DateTime.now.beginning_of_week
end
end

take_survey.html.erb

<%= this_should_work %>

错误 invalid date

最佳答案

我尝试在 Rails 之外使用 ActiveSupport 时遇到了同样的问题。我在这里找到了答案:

http://guides.rubyonrails.org/active_support_core_extensions.html

这里是关键点:

require 'active_support/all'

您是否自定义了您的 Rails 堆栈以不再包含 ActiveSupport?

关于ruby-on-rails-3 - Rails 3 无法开始 beginning_of_week,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6778733/

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