# Fields\_for: how many objects can it handle - max string size?

**URL:** <https://www.ruby-forum.com/t/fields-for-how-many-objects-can-it-handle-max-string-size/187879>\
**Category:** Rails\
**Created:** [April 30, 2010, 8:18pm UTC](https://www.ruby-forum.com/t/fields-for-how-many-objects-can-it-handle-max-string-size/187879 "2010-04-30T20:18:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kurt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b19c9b/32.png) [@Kurt](https://www.ruby-forum.com/u/Kurt)\
**Post date:** [April 30, 2010, 8:18pm UTC](https://www.ruby-forum.com/t/fields-for-how-many-objects-can-it-handle-max-string-size/187879/1 "2010-04-30T20:18:19Z")

</div>

Our app is getting a “string sizes too big” error in an .erb file that  
is trying to render a large block of checkboxes that represent color  
attributes that belong\_to the product being edited in this view. The  
code worked fine when we had a small number of colors – now that the  
number of colors is 750+, we get an error on the fields\_for line (see  
below).

Since this sounds somewhat like some older memory leak issues, I  
confirmed that our host, Engine Y., does not have an old Ruby  
version (they are on 1.8.6 patch level 287). The same error occurs on  
Mac OS/X with Ruby 1.8.6 patch 369.

I’ve had no luck searching for that error with “fields\_for” or finding  
any docs on size limitations inherent to fields\_for.

Processing Admin::ProductsController#edit (for 173.45.210.193 at  
2010-04-29 05:21:30) [GET]  
Parameters: {“id”=\>“17”}  
Rendering template within admin/layouts/base  
Rendering admin/products/edit

ActionView::TemplateError (string sizes too big) on line #67 of app/  
views/admin/products/edit.html.erb:  
64:  
65:

   
66: \<% previousObject = nil -%\>  
67: \<% f.fields\_for :prod\_method\_colors do |pmc| -%\>  
68: \<% pmcObj = pmc.object %\>  
69: \<%= "  
  
 Colors for  
#{PRINT\_METHOD\_TEXT[pmcObj.print\_method]}   
" if previousObject ==  
nil || (pmcObj.print\_method != previousObject.print\_method) %\>  
70: \<% previousObject = pmcObj -%\>

---

<div class="post-metadata">

**Author:** ![Kurt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b19c9b/32.png) [@Kurt](https://www.ruby-forum.com/u/Kurt)\
**Post date:** [May 1, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/fields-for-how-many-objects-can-it-handle-max-string-size/187879/2 "2010-05-01T15:44:42Z")

</div>

On Apr 30, 7:16 pm, Kurt [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Our app is getting a “string sizes too big” error in an .erb file that  
> is trying to render a large block of checkboxes that represent color  
> attributes that belong\_to the product being edited in this view. The  
> code worked fine when we had a small number of colors – now that the  
> number of colors is 750+, we get an error on the fields\_for line (see  
> below).

There’s only one place in the ruby C code I could find that raises  
‘string sizes too big’. It’s raised in a string concatenation function  
if the length of the existing string plus the length of what you’re  
concatenating exceeds LONG\_MAX, ie 2^31-1 on a 32bit system. I’m not  
sure why fields for would be attempting to concatenate two strings  
with a combined length of 2GB.

Fred
