# Sinatra : size of variable '@data' ? Bug?

**URL:** <https://www.ruby-forum.com/t/sinatra-size-of-variable-data-bug/166382>\
**Category:** Ruby\
**Created:** [April 24, 2009, 3:50pm UTC](https://www.ruby-forum.com/t/sinatra-size-of-variable-data-bug/166382 "2009-04-24T15:50:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![randy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@randy](https://www.ruby-forum.com/u/randy)\
**Post date:** [April 24, 2009, 3:50pm UTC](https://www.ruby-forum.com/t/sinatra-size-of-variable-data-bug/166382/1 "2009-04-24T15:50:32Z")

</div>

Hi,  
I’m working under Windows XP and ruby 1.8.6 patch 227.

My application display a ‘SELECT’ HTML to let choose  
a number. The list of number must be build : extracted  
from a database. I’ve also other ‘SELECT’

There is no problem in LOCAL (Ruby + Firefox in the  
same PC) but the list of number can’t be displayed  
in REMOTE mode then other shorter lists are displayed  
in the SELECT.

I’ve tried Webrick and Mongrel, there is no difference.

Three SELECT are build, only one can’t be seen. There  
are 234 line of option and 3120 bytes. The length of  
two others are : 4539 and 450 bytes, there is no  
problem with them.

The difference and the first and two other is the  
number of lines.

Below my code.

Why I can’t the data in REMOTE mode ?

Thanks.

Randy

########################################################

# HTML code used with ‘erb’
 \<%= @start\_choice =\> ########################################################

########################################################

# My ‘helpers’

helpers do

# Build the HTML code from an array of option for

#‘SELECT’.  
def html\_select(array)  
option=String.new()  
array.each {|opt| option \<\< “#{opt}”}  
option  
end  
end  
########################################################

---

<div class="post-metadata">

**Author:** ![randy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@randy](https://www.ruby-forum.com/u/randy)\
**Post date:** [April 24, 2009, 9:05pm UTC](https://www.ruby-forum.com/t/sinatra-size-of-variable-data-bug/166382/2 "2009-04-24T21:05:06Z")

</div>

B. Randy wrote:

> Why I can’t the data in REMOTE mode ?

Firstly, look at the HTML in both cases. Use ‘view source’ or equivalent  
in both browsers; and/or save the HTML from each browser to a file and  
then compare the files.

If the files are different, then you need to work out why your  
application is sending different data to different clients.

But if the files are identical, then my suspicion is that you are  
generating invalid (X)HTML - and therefore one of the browsers is  
processing it differently to the other.

For example, you might have mismatched start and end tags in your  
template. Or it might be that one of your select options contains a HTML  
special character, since you’re not escaping them. That is,

```
<%= @start_choice =>

```

should really be

```
<%=h @start_choice %>

```

Similarly, your html\_select helper should be escaping the options in the  
array.

I’d use the tool xmllint under Linux to check for well-formedness. There  
are probably other options for Windows. At worst you can upload the  
content to an online checker service, or you can parse it in Ruby using  
REXML::Document

From your posting subject line, I’m not sure what is the @data that  
you’re talking about, but as for “bug?” - yes, it probably is a bug in  
your code.

Good luck,

Brian.

---

<div class="post-metadata">

**Author:** ![randy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@randy](https://www.ruby-forum.com/u/randy)\
**Post date:** [April 27, 2009, 12:28pm UTC](https://www.ruby-forum.com/t/sinatra-size-of-variable-data-bug/166382/3 "2009-04-27T12:28:47Z")

</div>

Brian,

Thanks for the ideas. I’ll use It.

When I’ve checked my HTML code like you wrote it, I found  
MY error. It’s not Sinatra the problem.

I use a helper but in this helper I use a session variable  
like ‘session[:my\_data]’. The helper’s method is called in my  
HTML code and the session variable is not evaluated.

So, be careful when using var. in helper’s method.
