0

逻辑:如果今天不存在日志条目,我想显示占位符练习。如果今天的日志条目存在,那么即使它们存在也不显示占位符练习。

      .log-entries
        - unless exercise.log_entries.for_user(workout.user).blank? || exercise.last_log_date(workout.user) == Time.zone.today.beginning_of_day
          %p Nice job performing this #{timeago exercise.last_log_date(workout.user)}. Try going up in difficulty this time.
          = exercise.last_log_date(workout.user).to_date
          = exercise.last_log_entry(workout.user).created_at.to_date
          %br
          = Time.current.to_date
          %br
          - for log_entry in exercise.placeholder_log_entries!(workout.user)
            = render 'log_entries/form', log_entry: log_entry, exercise: exercise
        - for log_entry in exercise.log_entries.for_today.order("created_at ASC").for_user(workout.user) do
          = render 'log_entries/form', log_entry: log_entry, exercise: exercise
        - if exercise.log_entries.blank?
          %p.hint.not-performed-yet You haven't performed this exercise yet.

      = link_to exercise.render_add_text, user_workout_exercise_log_entries_path(workout, workout.user, exercise), class: "button radius", remote: true, method: :post

是什么让我发疯...是我今天记录了日志条目,但占位符练习仍然出现。所以第一个unless是通过。

调试后我会得到这样的值:

exercise last log date: 2013-08-26 00:00:00 -0700 
today: 2013-08-27 00:00:00 -0700 

但是那个exer最后的日志日期居然是今天记录的,就在现在!为什么晚了一天?

 #<LogEntry id: 226, reps: 8, weight: 55, effort: nil, description: nil, loggable_id: 3, loggable_type: "Exercise", created_at: "2013-08-27 06:00:12", updated_at: "2013-08-28 03:06:56", user_id: 1, rest_after_set: nil, difficulty: nil, distance: nil, duration: nil, measurement: nil, placeholder: false> 

创建于 2013-08-27 !!!为什么它在视图中渲染 26?我正在失去理智。

4

1 回答 1

0

Ruby on Rails 中的时区管理通常需要您设置config.time_zone“为应用程序设置默认时区并为 Active Record 启用时区感知”并使用 localize 帮助程序I18n.l或仅使用l.

例子:

I18n.l(Time.now)

l(Time.now)

看看: http: //guides.rubyonrails.org/i18n.html#configure-the-i18n-module

于 2013-08-28T04:24:08.293 回答