0

I am trying to get a json response for call made via jQuery ajax to a rails controller.

But the rails controller returns a response as Completed 406 Not Acceptable in 3154ms, when I see the logs in the rails server backtrace.

The jQuery call is:

$.ajax({
  type: 'POST',
  url: '/media_upload/apicall',
  dataType: 'json',
  data: {'filepicker_url': filepicker_url, 'client_id': client_id, 'token': token, 'type': type, 'name': name },
  success: function (data) { console.log(data);} 
);

The controller action is:

def apicall
  @content = media_upload_api
  respond_to do |format|
    format.json
  end
end

And the view is:

{
"response": {
    "code": "1",
        "status": "success",
    "message": "media correctly uploaded",
    "media": {
        "name": "<%= @content.name %>",
        "content_id": "<%= @content.id %>"
    }
}
}

media_upload_api:

def media_upload_api
  puts params.inspect
  client = Client.find_by_id(params[:client_id])

  if params[:filepicker_url]
    ps = { :name => params[:name], 
         :url => params[:filepicker_url], 
         :source_url => params[:filepicker_url],
         :client_id => params[:client_id], 
         :type => params[:type]
    }
    ps = AsyncContent.allowable_params(ps)
    puts ps
    @content = AsyncContent.new(params[:filepicker_url])
    puts @content.inspect
    if not (@content.save and @content.submit(params[:callback_url]))
      raise InvalidMediaRequest.new(@content.errors.full_messages.join(' '))
    end
    return @content
  else
    raise InvalidMediaRequest.new(:missing_media_file_or_url)
    return @content
  end
end
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
harshs08
  • 700
  • 10
  • 29

0 Answers0