0
試圖在.erb頁面中截斷Ruby/Sinatra中的字符串。 我一直在努力的變種:字符串操作在Sinatra/ERB中不起作用
<%= @caption_str.truncate(20) %>
<%= @caption_str[0..20] %>
但是要得到一種錯誤信息:
NoMethodError at /392471267473009
undefined method `[]' for nil:NilClass
或
NoMethodError at /392471267473009
undefined method `truncate' for nil:NilClass
一切都很好,如果我不截斷字符串,即
<%= @caption_str %>
我錯過了什麼?
我想看看關於@caption_str的代碼。也許在你的sinatra基本文件中? – halfelf
謝謝@halfelf,Jatin剛到問題的核心 –