我正在努力將視頻的字幕放入資料庫界面,因此需要將資訊呈現為 HTML5 標記的 VTT 檔案,以便能夠顯示隱藏式字幕。
在我的控制器中,顯示方法:
def show
@track = Track.find(params[:id])
@cues = @track.track_cues
@dash = " --> "
render template: 'tracks/show', layout: 'tracks', formats: [:vtt]
end
所以在我的 show.vtt.haml 檔案中,我有:
WEBVTT
= print "\n"
- @cues.each do |cue|
= cue.identifier
= cue.start_time.strftime("%H:%M:%S.%L") @dash cue.end_time.strftime("%H:%M:%S.%L")
= print "\n"
當前呈現為以下螢屏截圖

相反,它應該像這樣渲染:
WEBVTT
1
0:00:00.000 --> 0:00:03.000 line:90%
2
0:00:03.000 --> 0:00:06.000 line:90%
我不確定我在這里做錯了什么,它呈現物體代碼而不是大于字符。
uj5u.com熱心網友回復:
默認情況下,Rails 會轉義視圖中的所有內容。但是,您可以使用以下方法規避消毒raw:
= raw(cue.start_time.strftime("%H:%M:%S.%L") @dash cue.end_time.strftime("%H:%M:%S.%L"))
或者,特定于haml,!=運算子具有與前置相同的效果raw:
!= cue.start_time.strftime("%H:%M:%S.%L") @dash cue.end_time.strftime("%H:%M:%S.%L")
(在ERB, 中<%== %>會產生相同的效果。)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/493213.html
上一篇:反應原生-停止影片
