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

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:

match ‘my_words/test_create(.:format)’ => ‘my_words#test_create’

<%= form_tag(url_for("/my_words/test_create.js"), :format => :js,
“data-type” => “script”, :remote => true) do %>
<%= submit_tag “Test JS” %>
<% end %>


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

authenticate_user! :except => [:test_create]

def test_create
respond_to do |format|
format.js { render :js => “alert(‘This much works’);” }

From development.log:

Started POST “/my_words/test_create.js” for 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:
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
Content-Length 82
Cookie socketio=xhr-multipart; xxxxxxx

Any ideas?

Thanks so much!


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.)

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?

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs