# Erb strangeness

**URL:** <https://www.ruby-forum.com/t/erb-strangeness/149973>\
**Category:** Rails\
**Created:** [October 1, 2008, 9:15pm UTC](https://www.ruby-forum.com/t/erb-strangeness/149973 "2008-10-01T21:15:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [October 1, 2008, 9:15pm UTC](https://www.ruby-forum.com/t/erb-strangeness/149973/1 "2008-10-01T21:15:41Z")

</div>

I’m using a relatively simple erb to generate output. However, though  
it works, it also produces a lot of ‘false’ words in the output. This  
is easier shown than described. Here is the erb:

# Image Search page
You can use this page to search for particular images in the GRECC collection of images, by specifying particular properties you are interested in. \<% form\_tag '/test' do -%\>
* * *

## Select Series of Interest:
\<% counter = 0 %\> \<% @series.each do |k| %\> \<%= counter%4==0 ? "" : "" %\> " : "" %\> \<% counter += 1 %\> \<% end %\>

| \<%= k+":" %\>\<%= check\_box\_tag @seriesmap[k] %\> \<%= counter%4==3 and counter \> 1 ? " |

  

* * *

## Select Years of Interest:
\<% @years.each do |y| %\> \<%= y.to\_s + ":" %\> \<%= check\_box\_tag y.to\_s %\> \<% end %\>
* * *

\<%= submit\_tag 'Search' %\>

## \<% end -%\>

And here is the first part of the generated output:

h1\>Image Search page  
You can use this page to search for particular images in the GRECC  
collection of images, by specifying particular  
properties you are interested in.

* * *

## Select Series of Interest:
 false

```
<td><small>(7313/7/40)+(7313/103/1):<input id="seriesB"

```

name=“seriesB” type=“checkbox” value=“1” /\>

false

```
<td><small>+C 1.5mmAxT13dspgr:<input id="seriesB" name="seriesB"

```

type=“checkbox” value=“1” /\>  
false

* * *

Anyone know where those 'false’s are coming from? It’s got me stumped.

Thanks,  
Ken

| (7313/102/1)+(7313/6/76): |

---

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [October 1, 2008, 11:33pm UTC](https://www.ruby-forum.com/t/erb-strangeness/149973/2 "2008-10-01T23:33:09Z")

</div>

On Oct 1, 8:14 pm, Kenneth McDonald [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> <%= counter%4==3 and counter > 1 ? "</tr>" : "" %>
> 
> ```
> 
> Anyone know where those 'false’s are coming from? It’s got me stumped.

The line above is the culprit, and the problem is that you have used  
and instead of &&. and has very low precedence, so the above is  
equivalent to

(counter%4==3) and (counter \> 1 ? “” : “”)

(ie the whole expression evaluates to false if counter is not  
congruent to 3 mod 4)

&& has higher precedence, replacing the and with && would make it  
equivalent to

((counter%4==3) and (counter \> 1)) ? “” : “”)

which is what you want.

Fred

---

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [October 1, 2008, 11:35pm UTC](https://www.ruby-forum.com/t/erb-strangeness/149973/3 "2008-10-01T23:35:30Z")

</div>

Ah, many thanks, I was thinking the difference between && and ‘and’  
was bitwise vs. logical.

Ken
