代码在开发环境中有效。部署到Heroku时,日志显示错误ActionView::Template::Error (undefined method...)
。这是在show
,edit
操作上执行的,似乎与我使用的i18n
格式有关。
我注释掉了视图中的代码,重新部署了应用程序,并确认它可以在Heroku上正常工作。
# config/locales/en.yml
en:
hello: "Hello world"
time:
formats:
short: '%H:%M'
查看
<li>Players arrive: <span class="float-right"><%= l @schedule.start_time - 30.minutes, format: :short %> am</span></li>
<li>Coin Toss: <span class="float-right"><%= l @schedule.start_time - 20.minutes, format: :short %> am</span></li>
<li>Game Start: <span class="float-right"><%= @schedule.start_time.to_s(:time) %> am</span></li>
<li>Lunch Break: <span class="float-right"><%= l @schedule.start_time + 3.5.hours, format: :short %> pm</span></li>
<li>2nd Innings Start: <span class="float-right"><%= l @schedule.start_time + 4.hours, format: :short %> pm</span></li>
<li>Game End: <span class="float-right"><%= l @schedule.start_time + 7.25.hours, format: :short %> pm</span></li>
Heroku日志
2019-04-23T16:43:39.473185+00:00 app[web.1]: D, [2019-04-23T16:43:39.473113 #8] DEBUG -- : [85be5233-b649-40a0-9707-eeaef1773522] [1m[36mSelection Load (6.5ms)[0m [1m[34mSELECT "selections".* FROM "selections" WHERE "selections"."schedule_id" = $1 AND "selections"."user_id" = $2 LIMIT $3[0m [["schedule_id", 1], ["user_id", 1], ["LIMIT", 1]]
2019-04-23T16:43:39.492684+00:00 app[web.1]: I, [2019-04-23T16:43:39.492587 #8] INFO -- : [85be5233-b649-40a0-9707-eeaef1773522] Rendering schedules/show.html.erb within layouts/application
2019-04-23T16:43:39.494351+00:00 app[web.1]: I, [2019-04-23T16:43:39.494284 #8] INFO -- : [85be5233-b649-40a0-9707-eeaef1773522] Rendered schedules/partials/_match_centre.html.erb (0.5ms)
2019-04-23T16:43:39.502847+00:00 app[web.1]: I, [2019-04-23T16:43:39.502777 #8] INFO -- : [85be5233-b649-40a0-9707-eeaef1773522] Rendered schedules/partials/_run_times.html.erb (8.0ms)
2019-04-23T16:43:39.502959+00:00 app[web.1]: I, [2019-04-23T16:43:39.502898 #8] INFO -- : [85be5233-b649-40a0-9707-eeaef1773522] Rendered schedules/show.html.erb within layouts/application (10.2ms)
2019-04-23T16:43:39.503140+00:00 app[web.1]: I, [2019-04-23T16:43:39.503080 #8] INFO -- : [85be5233-b649-40a0-9707-eeaef1773522] Completed 500 Internal Server Error in 51ms (ActiveRecord: 24.6ms)
2019-04-23T16:43:39.503731+00:00 app[web.1]: F, [2019-04-23T16:43:39.503670 #8] FATAL -- : [85be5233-b649-40a0-9707-eeaef1773522]
2019-04-23T16:43:39.503806+00:00 app[web.1]: F, [2019-04-23T16:43:39.503731 #8] FATAL -- : [85be5233-b649-40a0-9707-eeaef1773522] ActionView::Template::Error (undefined method `start_time' for #<Schedule:0x00007fbde401fb68>):
2019-04-23T16:43:39.503974+00:00 app[web.1]: F, [2019-04-23T16:43:39.503913 #8] FATAL -- : [85be5233-b649-40a0-9707-eeaef1773522] 2: <div class="card-body">
2019-04-23T16:43:39.503977+00:00 app[web.1]: [85be5233-b649-40a0-9707-eeaef1773522] 3: <h5 class="card-title"><strong>Match Run Times</strong></h5>
2019-04-23T16:43:39.503981+00:00 app[web.1]: [85be5233-b649-40a0-9707-eeaef1773522] 4: <ul class="card-text">
2019-04-23T16:43:39.503983+00:00 app[web.1]: [85be5233-b649-40a0-9707-eeaef1773522] 5: <li>Players arrive: <span class="float-right"><%= l @schedule.start_time - 30.minutes, format: :short %> am</span></li>
2019-04-23T16:43:39.503985+00:00 app[web.1]: [85be5233-b649-40a0-9707-eeaef1773522] 6: <li>Coin Toss: <span class="float-right"><%= l @schedule.start_time - 20.minutes, format: :short %> am</span></li>
2019-04-23T16:43:39.503987+00:00 app[web.1]: [85be5233-b649-40a0-9707-eeaef1773522] 7: <li>Game Start: <span class="float-right"><%= @schedule.start_time.to_s(:time) %> am</span></li>
2019-04-23T16:43:39.503989+00:00 app[web.1]: [85be5233-b649-40a0-9707-eeaef1773522] 8: <li>Lunch Break: <span class="float-right"><%= l @schedule.start_time + 3.5.hours, format: :short %> pm</span></li>
2019-04-23T16:43:39.504028+00:00 app[web.1]: F, [2019-04-23T16:43:39.503964 #8] FATAL -- : [85be5233-b649-40a0-9707-eeaef1773522]
2019-04-23T16:43:39.504098+00:00 app[web.1]: F, [2019-04-23T16:43:39.504039 #8] FATAL -- : [85be5233-b649-40a0-9707-eeaef1773522] app/views/schedules/partials/_run_times.html.erb:5:in `_app_views_schedules_partials__run_times_html_erb__4351229195490545164_70226775711600'
2019-04-23T16:43:39.504101+00:00 app[web.1]: [85be5233-b649-40a0-9707-eeaef1773522] app/views/schedules/show.html.erb:9:in `_app_views_schedules_show_html_erb__4220913006891638050_70226775641260'