# Form submission should return javascript but returns "406 Not Acceptable"

**URL:** <https://www.ruby-forum.com/t/form-submission-should-return-javascript-but-returns-406-not-acceptable/206942>\
**Category:** Rails\
**Created:** [May 13, 2011, 6:30pm UTC](https://www.ruby-forum.com/t/form-submission-should-return-javascript-but-returns-406-not-acceptable/206942 "2011-05-13T18:30:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 13, 2011, 6:30pm UTC](https://www.ruby-forum.com/t/form-submission-should-return-javascript-but-returns-406-not-acceptable/206942/1 "2011-05-13T18:30:28Z")

</div>

I have a form that submits fine and is processed by the controller but  
began failing to return Javascript (around the time I upgraded to 3.0.7)  
and instead generates a “406 Not Acceptable.”

I’ve tried everything I can think of to get this working again, and I’m  
completely baffled.

I’ve stripped the problem down to the following:

config/routes:  
match ‘my\_words/test\_create(.:format)’ =\> ‘my\_words#test\_create’

whatever.html.erb:  
\<%= form\_tag(url\_for(“/my\_words/test\_create.js”), :format =\> :js,  
“data-type” =\> “script”, :remote =\> true) do %\>  
\<%= submit\_tag “Test JS” %\>  
\<% end %\>

app/controllers/my\_words\_controller.rb:

# I don’t think this is necessary, but I’m trying to isolate the

problem  
authenticate\_user! :except =\> [:test\_create]  
…  
def test\_create  
respond\_to do |format|  
format.js { render :js =\> “alert(‘This much works’);” }  
end  
end

From development.log:

Started POST “/my\_words/test\_create.js” for 127.0.0.1 at Fri May 13  
12:13:01 -0400 2011  
Processing by MyWordsController#test\_create as JS  
Parameters: {“utf8”=\>“✓”, “authenticity\_token”=\>“xxxxxxx”}  
Completed 406 Not Acceptable in 2ms

From Firebug:

Response Headers  
Cache-Control no-cache  
x-ua-compatible IE=Edge,chrome=1  
Set-Cookie \_xxxxxx\_session=xxxxxx; path=/; HttpOnly  
X-Runtime 0.095000  
Content-Type text/html;charset=utf-8  
Content-Length 1  
Date Fri, 13 May 2011 16:13:01 GMT

Request Headers  
Host localhost:3005  
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17)  
Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17  
Accept text/javascript, application/javascript, _/_; q=0.01  
Accept-Language en-us,en;q=0.5  
Accept-Encoding gzip,deflate  
Accept-Charset ISO-8859-1,utf-8;q=0.7,\*;q=0.7  
Keep-Alive 115  
Connection keep-alive  
Content-Type application/x-www-form-urlencoded; charset=UTF-8  
X-Requested-With XMLHttpRequest  
X-CSRF-Token xxxxxxxx  
Referer [http://localhost:3005/home/article/10671](http://localhost:3005/home/article/10671)  
Content-Length 82  
Cookie socketio=xhr-multipart; xxxxxxx

Any ideas?

Thanks so much!

James

---

<div class="post-metadata">

**Author:** ![jameslabocki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jameslabocki](https://www.ruby-forum.com/u/jameslabocki)\
**Post date:** [May 13, 2011, 6:34pm UTC](https://www.ruby-forum.com/t/form-submission-should-return-javascript-but-returns-406-not-acceptable/206942/2 "2011-05-13T18:34:24Z")

</div>

The first line in app/controllers/my\_words\_controller.rb is actually:  
before\_filter :authenticate\_user!, :except =\> [:test\_create]

(I should have copied-and-pasted.)

---

<div class="post-metadata">

**Author:** ![jameslabocki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jameslabocki](https://www.ruby-forum.com/u/jameslabocki)\
**Post date:** [May 13, 2011, 8:47pm UTC](https://www.ruby-forum.com/t/form-submission-should-return-javascript-but-returns-406-not-acceptable/206942/3 "2011-05-13T20:47:33Z")

</div>

I used my Git time machine to revert to my last known good state.

I updated to the latest rails.js and everything still worked.

I then updated to JQuery 1.6.1 and everything broke.

I backed up to JQuery 1.5.2 and some (but not all) things were broken.

I backed up to JQuery 1.4.4 and things worked again.

I updated from Rails 3.0.5 to 3.0.7 and things still apparently work.

So it’s looking like a JQuery problem.

Anyone else hit this problem?

---

<div class="post-metadata">

**Author:** ![jameslabocki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jameslabocki](https://www.ruby-forum.com/u/jameslabocki)\
**Post date:** [May 14, 2011, 2:49pm UTC](https://www.ruby-forum.com/t/form-submission-should-return-javascript-but-returns-406-not-acceptable/206942/4 "2011-05-14T14:49:57Z")

</div>

In case anyone else experiences my problem…

My “JQuery 1.5.2” problem was actually caused by the latest versions of  
HAML and Kaminari not playing well together. So my Ajax form submission  
troubles may all be caused by JQuery 1.6.1.
