Rails的*完成406不可接受"在生产上分期..working [英] Rails *Completed 406 Not Acceptable" in production ..working in Staging

查看:125
本文介绍了Rails的*完成406不可接受"在生产上分期..working的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持到错误的,我没有面临临时服务器生产服务器已完成406不可接受

I am stuck with an error "Completed 406 Not Acceptable" in the production server which I am not facing in the staging server .

同code工作正常分期,但安装了相同的宝石生产。无论环境下不能正常工作。我使用的是轨道版本3.0.10。

Same code is working fine in staging but not working in production .Both environment has same gems installed . I am using a rails version 3.0.10.

在我的生产环境中,GET请求被处理为HTML,但在分期为爵士。我已经定义了的respond_to块只为JS格式对其进行处理。我不知道为什么它是不同的行为在两种环境。

In my production environment , the GET request is processed as a html but in staging it is processed as js .I have defined the respond_to block only for js format . I am not sure why it is behaving differently in two environments.

此外,我曾尝试加入默认格式,在routes.rb中JS但也不能正常工作。

Also I have tried adding the defaults format as js in the routes.rb but that also is not working.

match 'releases/cycle_paginate', :to => 'releases#cycle_paginate', :defaults => { :format => 'js' }

不过,这也不能正常工作。

But this is also not working .

下面是日志,生产和分期。

Below is the log for production and staging .

制作:

Started GET "/releases/cycle_paginate/2?id=4" for 10.30.10.67 at Wed Aug 14 07:13:45 -0400 2013
  Processing by ReleasesController#cycle_paginate as JS
  Parameters: {"id"=>"4", "page"=>"2"}

切入:

Started GET "/releases/cycle_paginate/2?id=53" for 10.30.10.67 at Wed Aug 14 06:42:45 -0400 2013
  Processing by ReleasesController#cycle_paginate as HTML
  Parameters: {"id"=>"53", "page"=>"2"}

控制器:

def cycle_paginate

  @release = Release.find(params[:id])

  @cycles = []
  @cycles = Kaminari.paginate_array(@release.cycles) \
                  .page(params[:page]) \
                  .per(5)
  last_page = @cycles.num_pages
  if params[:page].to_i > last_page
    @cycles = @cycles.page(last_page)
  else
    @cycles = @cycles.page(params[:page].presence || 1)
  end
  respond_to do |format|
    format.js
  end
end

这是快把我逼疯了。鸭preciate你的帮助。

This is making me mad. Appreciate your help.

routes.rb中

Routes.rb

    `Tcm::Application.routes.draw do        match "login", :controller => "user_sessions", :action => "create", :as => "login"
      match "logout", :controller => "user_sessions", :action => "destroy", :as => "logout"
      resources :ic_tree_items do
        get :children, :on => :member
        get :nonmem_rel_children, :on => :member
        get :release_children, :on => :member
        get :cycle_children, :on => :member
      end
      resources :users
      resources :ic_revisions
      resources :tester_release_assignments
      resources :roles
      resources :project_platform_config_assignments
      resources :platform_configs
      resources :user_sessions

      match 'ic_runs/execute_multiple', :to => 'IcRuns#execute_multiple', :as => "execute_multiple_ics", :via => :put

      resources :ic_runs
      resources :reports
      resources :testruns

      match "cycles/add_ics", :to => "cycles#add_ics"

      resources :cycles
      resources :releases do
        get :autocomplete_user_name, :on => :collection
      end
      resources :projects
      resources :tasks
      resources :steps
      resources :asserts

      match 'releases/mass_assign', :to => 'Releases#mass_assign', :as => 'mass_assign_releases', :via => :post
      match 'ics/mass_action', :to => 'Ics#mass_action', :as => 'mass_action_ics', :via => :post
      match 'ics/filter' ,:to=>'Ics#filter',:via=> :post
      match 'taggings/selection_options', :to => 'Taggings#selection_options', :as => 'selection_option_taggings',:via => :post
      match 'tags/filter',:to=>'Tags#filter',:via=> :post
      resources :ics
      resources :tags

      root :to => "Home#index"
      match ':name' => 'Projects#show'
      match 'ic_revisions/update', :to => 'ic_revisions#update'
      match 'ic_revisions/clone_task', :action => "clone_task", :controller=>"ic_revisions"
      match 'ic_revisions/definition_textbox', :to => 'ic_revisions#definition_textbox'
      match 'tasks/destroy', :action => "destroy", :controller=>"tasks"
      match 'steps/destroy', :action => "destroy", :controller=>"steps"
      match 'asserts/destroy', :action => "destroy", :controller=>"asserts"
      match 'cycles/:id/delete', :action => "destroy", :controller=>"cycles"
      match 'ic_revisions/manage/:ic_id', :to => 'ic_revisions#index', :as => "manage_ic_revisions"
      match 'cycles/:id/add_ics', :to => 'cycles#add_ics'
      match 'cycles/del_cycle_ic', :to => 'cycles#del_cycle_ic'
      match 'cycles/add_ic_run', :action => "add_ic_run", :controller=>"cycles", :via => :post
      match 'releases/:id/add_ics', :to => 'releases#add_ics'
      match 'users/lead/:id', :to => 'users#show_lead', :as => "lead"
      match 'users/tester/:id', :to => 'users#show_tester', :as => 'tester'
      match 'users/edit/:id', :to => 'users#edit', :as => 'users_edit'
      match 'cycles/add_cq', :to => 'cycles#add_cq',:as=>'cycles_add_cq'
      match 'ic_runs/update_ics', :to => 'ic_runs#update_ics'
      match 'ic_runs/cycle/:cycle_id', :to => 'ic_runs#cycle', :as => 'cycle_ic_runs'
      match 'ic_runs/edit_result', :to => 'ic_runs#edit_result'
      match 'ic_runs/ic_run_list/:id', :to => 'ic_runs#ic_run_list', :as => 'ic_runs_list'
      match 'reports',:to=>'reports#index'
      match 'reports/update_releases', :to=>'reports#update_releases'
      match 'reports/update_cycles', :to=>'reports#update_cycles'
      match 'reports/show', :to=> 'reports#export_reports'
      match 'ics/on_update_root', :to=>'ics#on_update_root'
      match 'ic_runs/export_all', :to => 'ic_runs#export_all'
      match 'ics/on_update_suite', :to=>'ics#on_update_suite'
      match 'ic_runs/destroy', :to => 'ic_runs#destroy', :key=>:ic_run_ids
      match 'cycles/:id/clone', :action => "clone", :controller=>"cycles"
      match 'releases/:id/clone', :action => "clone", :controller=>"releases"
      match 'cycles/:id/delete_ics', :action => "delete_ics", :controller=>"cycles"
      match 'releases/update_testers', :to => 'releases#update_testers'
      match 'releases/update_testers(/:page)', :action => "update_testers", :controller=>"Releases", :page => :page
      match 'releases/cycle_paginate', :to => 'releases#cycle_paginate'
      match 'releases/cycle_paginate(/:page)', :action => "cycle_paginate", :controller=>"Releases", :page => :page
      match 'ics/new_ics', :to =>'ics#', :action => "new_ics", :controller => "Ics"
      match 'ics/obsolete_ics', :to=>'ics#', :action=>"obsolete_ics", :controller=>"Ics"
      match 'ics/new_ic_stub', :to=>'ics#', :action=>"new_ic_stub", :controller=>"Ics"
      match 'ics/index', :to=>'ics#', :action=>"index", :controller=>"Ics"
      match 'releases/rel_all_ics', :action => "rel_non_member", :controller => "Releases"
      match 'cycles/cycle_non_member', :action=>"cycle_non_member", :controller=>"Cycles"
    end

`

推荐答案

最后,我得到了很多的调试后的溶液。

Finally I got the solution after a lot of debugging ..

我的请求,接受头部期待一个HTML,而服务器返回一个js响应,以便不被浏览器接受。

My request accept header was expecting a HTML while server was returning a js response so that was not acceptable by browser .

在我的情况下,一个js文件中缺少application.html.erb .The的javascript_include_tag JavaScript的缺失是 * jquery_ujs.js * 。基本上这台接受头为Ajax加载.The javascipts包括在该标签将被缓存并存储。 所以我加了失踪JavaScript和删除缓存文件夹,并YIEPPE我的问题得到了解决。

In my case a js file was missing the javascript_include_tag in the application.html.erb .The javascript missing was *jquery_ujs.js* .Basically this sets the accept header for ajax loading .The javascipts included in this tag will be cached and stored. So I added the missing javascript and removed the cached folder and YIEPPE my problem got resolved.

会给出一个小例子,我学到什么地方从博客.Seems这将有利于别人理解406错误。

Will give a small example that I learnt somewhere from a blog .Seems it will be helpful for others to understand the 406 error.

可406错误理解为如下:  假如我问你一本书来读,但我只可以阅读英文和法文书籍。如果你只有在德国的书,你会给我一个的一个空的响应。406 - 不接受状态

406 error can be understood as below: Suppose I've asked you for a book to read, but I can only read books in English and French. If you only have books in German, you would give me an empty response with a "406 - not acceptable" status.

406是服务器告诉你我中有你问什么,但你不会接受他们。

406 is the server telling you "I have what you asked for, but you won't accept them".

这就是Accept标头在HTTP请求是。举例来说,如果HTTP请求中包含的方向,它将只接受IMG / JPGMIME类型,服务器会发送一个406状态,如果请求的文件是一个Excel US preadsheet。

That's what Accept headers in the http request are for. For instance, if the http request includes directions that it will only accept "img/jpg" mime type, the server would send a 406 status if the file requested is an Excel spreadsheet.

要诊断:

  • 在要求这些网页时,分析HTTP请求头
  • 需要注意的是MIME类型的答复,字符集,GZIP编码*

406不能接受的,是一个不寻常的地位code - 最常见的有200,404,500,301。你只看到406时,什么是错的服务器,通常是一些愚蠢的,但很难诊断

"406 not acceptable" is an unusual status code - the most common are 200, 404, 500, 301. You only see a 406 when something is wrong with the server, usually something silly but hard to diagnose

这篇关于Rails的*完成406不可接受"在生产上分期..working的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆