Weird “406 not acceptable” error

前端 未结 12 990
南方客
南方客 2020-11-27 05:38

When I try to hit this action via Javascript, I get a 406 Not Acceptable error:

  def show
    @annotation = Annotation.find_by_id(params[:id])
         


        
相关标签:
12条回答
  • 2020-11-27 06:07

    For me it was a simple before_filter that was restricting a action that renders a js file, once I added the :except => [:action] to the before_filter block it was fine.

    0 讨论(0)
  • 2020-11-27 06:11

    Another insidious "Gotcha" here is if you call your controller with a form_for that accidentally has an additional not-necessary parameter. The additional parameter can be interpreted by Rails as a format request, and you'll get the 406.

    Example:

    = form_for parking_permit, url: permit_group_parking_permits_path(@permit_group.id, useless_id), method: :get do |f| ...

    In the example above, you RAKE ROUTES and determine that permit_group_parking_permits_path does NOT need anything but the permit_group id...

    If you see your method being called such as /model/action.1?blahblahblah that ".1" is your tip-off.

    This will return the 406. We won't talk about how much time I spent on this once.

    0 讨论(0)
  • 2020-11-27 06:12

    Is this served through Apache? You may want to take a look at http://forums.alwayswebhosting.com/showthread.php?p=8381, which describes scenarios where security policy interferes with requests.

    EDIT: The URL referenced above advocates turning off request-sniffing security policy across an entire site, which makes the site vulnerable. Setting the SecFilterEngine option to Off in the .htaccess, which is what is prescribed in the URL, should be done only to zero in on the source of the problem. It should not be considered a long term solution.

    0 讨论(0)
  • 2020-11-27 06:16

    include "format.js" in your respond_to block

    0 讨论(0)
  • 2020-11-27 06:19

    Check your application.js for require jquery_ujs

    //= require jquery_ujs
    
    0 讨论(0)
  • 2020-11-27 06:21

    Just use this code in controller action method format block:

    format.js   { render :nothing => true }  
    
    0 讨论(0)
提交回复
热议问题