# NoMethodError with a twist

**URL:** <https://www.ruby-forum.com/t/nomethoderror-with-a-twist/112697>\
**Category:** Rails\
**Created:** [August 22, 2007, 9:45am UTC](https://www.ruby-forum.com/t/nomethoderror-with-a-twist/112697 "2007-08-22T09:45:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wbharding](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8797f3/32.png) [@wbharding](https://www.ruby-forum.com/u/wbharding)\
**Post date:** [August 22, 2007, 9:45am UTC](https://www.ruby-forum.com/t/nomethoderror-with-a-twist/112697/1 "2007-08-22T09:45:15Z")

</div>

Usual disclaimers are in order that I’m pretty new to RoR and don’t know  
exactly how to approach debugging this problem, but I’ve looked over  
about 20 Google pages+these forums and can’t figure this one out…so  
hoping someone very smart can give me an idea here.

I’m trying to make an AJAX call to a method (“new\_item\_add\_image”) in a  
file called booths\_controller.rb using the following  
javascript-generated form:

— Begin —  
var form = document.createElement(‘form’);  
form.setAttribute(‘id’, id);  
form.setAttribute(‘target’, frameID);  
form.setAttribute(‘method’, ‘post’);  
form.setAttribute(‘enctype’, ‘multipart/form-data’);  
form.setAttribute(‘action’, ‘/booths/new\_item\_add\_image’);  
document.body.appendChild(form);  
… A couple input elements are Javascript-generated here…  
— End —

Submitting this form _usually_ gives me the following error:

— Begin —  
Status: 500 Internal Server Error  
Content-Type: text/html  
Content-Length: 60

# 500 Internal Server Error
# ["c:/ruby/lib/ruby/1.8/webrick/httputils.rb:129:in `parse\_header'", --- End ---

I say “usually” because there are two circumstances in which the form  
calls the “new\_item\_add\_image” method properly: 1) if put a call to  
ruby-debug (e.g., “debugger”) anywhere in the method and step through  
it, it acts fine or 2) if I clear my cache and cookies, the form will  
usually submit fine the first try and err on subsequent attempts.

I can not make rhyme nor reason of what could be going wrong here, in  
particular why adding the debugger line and stepping through the  
function causes it to work. Here’s some of the method in question, if  
it matters:

— Begin —  
def new\_item\_add\_image  
#debugger # if commented, the method isn’t called and the error is  
given  
flash[:notice] = “We are arrived. Woohoo!” # Shows this message if  
the debugger line is uncommented. Does not show otherwise.

```
image_id = (params[:image_id] =~ /\_(\d+)$/ ? $1.to_i : 0);

if params[:image]
  if session[:new_item_image] && session[:new_item_image][image_id]
    session[:new_item_image][image_id].destroy
    session[:new_item_image][image_id] = nil
  end

  session[:new_item_image] ||= Array.new
  session[:new_item_image][image_id] = Image.new(params[:image])

  if session[:new_item_image][image_id].valid?
    session[:new_item_image][image_id].save
    active_booth.images[image_id] =

```

session[:new\_item\_image][image\_id]  
end  
end

```
render :text => %(/*-secure-\n{ "image_main" :

```

“#{session[:new\_item\_image][image\_id].public\_path}” }\n\*/)  
end

— End —

Thanks much for any ideas at all!

Bill
