我不了解 Ruby,但我的应用程序遇到了这个问题。有人可以帮助我吗?
ActionView::TemplateError (can't convert nil into String) on line #7
4: <h3><span><%= opinion.opinion %></span>: <%= opinion.keywords.sort.join(' / ').upcase %> </h3>
5: <div class="original">Estado original: <span class="pos"><%= opinion.opinion %></span></div>
6: <%#= highlight(simple_format(highlight_ontology(opinion)), opinion.keywords, :highlighter => '<em>\1</em>') %>
7: <%= simple_format(highlight_ontology(opinion)) %>
8: <%= button_to_remote('POSITIVO', {:url => url_for(opinion), :method => :put, :with => '"opinion[opinion]=POSITIVE"' }, :class => :positive) %>
9: <%= button_to_remote('OBJETIVO', {:url => url_for(opinion), :method => :put, :with => '"opinion[opinion]=OBJECTIVE"' }, :class => :objective) %>
10: <%= button_to_remote('NEGATIVO', {:url => url_for(opinion), :method => :put, :with => '"opinion[opinion]=NEGATIVE"' }, :class => :negative) %>
谢谢!
最佳答案
使用 (variable || "")
而不仅仅是变量应该使其默认为空字符串。
这种技术称为 null(或 nil)合并。
关于ruby - 无法将 nil 转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8852264/