views:

170

answers:

2

Hello,

following code generate a 406 Not Acceptable error.

What can be wrong with my code?

  def remote_create
    @photo = Photo.new(params[:photo])

    respond_to do |format|
      if @photo.save
        # add @photo's thumbnail to last import tag
        format.js {
          render :update do |page|
            page.insert_html :bottom, 'polaroids' , :partial    => 'polaroid', :locals => {:photo => @photo}
          end 
        }
      else
        format.html
      end
    end
  end


Started POST "/photos/remote_create" for 127.0.0.1 at 2010-03-14 14:02:08
  Processing by PhotosController#remote_create as HTML
  Parameters: {"photo"=>{"photo"=>#<File:/var/folders/BT/BTpdsWBkF6myaI-sl3+1NU+++TI/-Tmp-/RackMultipart20100314-285-1y9eq1x-0>, "name"=>"4204497503_a0c43c561d.jpg"}}
  SQL (0.6ms)  INSERT INTO "photos" ("created_at", "filename", "height", "name", "photo_content_type", "photo_file_name", "photo_file_size", "photo_updated_at", "size", "updated_at", "width") VALUES ('2010-03-14 13:02:08.449499', NULL, NULL, '4204497503_a0c43c561d.jpg', 'application/octet-stream', '4204497503_a0c43c561d.jpg', 136710, '2010-03-14 13:02:08.446370', NULL, '2010-03-14 13:02:08.449499', NULL)
[paperclip] Saving attachments.
[paperclip] saving /Users/denisjacquemin/Documents/code/projects/photos/public/system/photos/224/original/4204497503_a0c43c561d.jpg
Completed in 101ms with 406

here is the request header

Host    localhost:3000
User-Agent  Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
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    multipart/form-data; boundary=AJAX-----------------------1268573300187
Referer http://localhost:3000/photos/
Content-Length  2058592
Cookie  remember_token=ea5af5a7c9a38d72bfd07756754af682a5d16cac; _photos_session=BAh7ByIQX2NzcmZfdG9rZW4iMW1yTUo3RkhzRlhPUXhsa0ptdDAyaUpDcXlTdlU0OHk2WHJhUzBzMmVQV1k9Ig9zZXNzaW9uX2lkIiViNzc0MGI2ZGMyYWNlNjEzZWEwYjVhM2U1Njg1MWE3YQ%3D%3D--1af96dbdbef595c48121e4f5c16298cadeef5b2a
+1  A: 

Are you setting a specific format (like if using jQuery, something like {format: 'raw'}), or setting the request header mime type (search for setRequestHeader)?

Easiest way to find out would be to use Firebug and look at what your request looks like.

Other thing to try, does the same error occur with another browser?

JRL
well, are you talking about the content type? the request header is now in the question
denisjacquemin
A: 

I found the solution, when I build the ajax request, I need to set the following header parameter

xhr.setRequestHeader("Accept", "text/javascript");

before setting this parameter, the request header was

Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

and now the request header looks like this

Accept  text/javascript

works fine now

denisjacquemin