Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't convert nil into String

Tags:

string

null

ruby

I don't know Ruby but I'm having this problem with my application. Somebody can help me?

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) %>

Thanks!

like image 343
user1147884 Avatar asked Jan 13 '12 14:01

user1147884


1 Answers

Using (variable || "") instead of just the variable should make it default to an empty string.

This technique is called null(or nil) coalescing.

like image 197
Emyr Avatar answered Oct 19 '22 08:10

Emyr