Maybe I'm missing something simple but I can't figure out after some time looking at this.
I want to check if a boolean is true in a database on a form, if it is display a up arrow, if not down arrow.
I have this
<% for probe in @probes %>
<tr id="<%= cycle('list-line-odd', 'list-line-even') %>">
<td>
<%= if probe.online = true %>
<%= image_tag("online-icon.png", :alt => "Online") %>
<%= end %>
</td>
<td><%= link_to probe.probe_name, probe %></td>
</tr>
<% end %>
but it's coming back this this error
compile error
syntax error, unexpected ')', expecting kTHEN or ':' or '\n' or ';'
@output_buffer.concat "\t \t"; @output_buffer.concat(( if probe.online = true ).to_s);
@output_buffer.concat "\n"
syntax error, unexpected kEND
@output_buffer.concat " \t \t"; @output_buffer.concat(( end ).to_s);@output_buffer.concat "\n"
with arrows pointing at the .to_s
Firstly, you test for equality with ==
, not =
, which is the assignment operator.
Second — and this is what the error is complaining about — you need to use just plain <%
rather than <%=
with an if-statement. The latter form tries to turn the code inside it into a string, and of course it's meaningless to write (if something == true).to_s
— there's no possible string value for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With