我在生产服务器中遇到错误“已完成406不可接受”,我在登台服务器中没有遇到此错误。
相同的代码在暂存时工作正常但在生产中不起作用。这两个环境都安装了相同的gem。我使用的是rails 3.0.10。
在我的生产环境中,GET请求作为html处理,但在暂存时它被处理为js。我已经为js格式定义了respond_to块。我不确定为什么它在两种环境中表现不同。
此外,我尝试在routes.rb中添加默认格式为js,但这也无效。
match 'releases/cycle_paginate', :to => 'releases#cycle_paginate', :defaults => { :format => 'js' }
但这也行不通。
以下是生产和登台的日志。
生产:
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
这让我很生气。感谢您的帮助。
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
`
答案 0 :(得分:6)
最后我经过大量调试后得到了解决方案..
我的请求接受标头期待HTML而服务器返回Javascript响应,因此浏览器无法接受。
在我的情况下,一个Javascript文件缺少application.html.erb中的javascript_include_tag。缺少的Javascript是 jquery_ujs.js 。基本上这会设置接受标头ajax loading。此标记中包含的Javascripts将被缓存并存储。 所以我添加了缺少的Javascript并删除了缓存的文件夹和YIPPEE,我的问题得到了解决。
我将举一个小例子,我从博客中学到了一些东西。似乎有人可以帮助其他人理解406错误。
406错误可以理解如下: 假设我已经要求你阅读一本书,但我只能阅读英文和法文书籍。如果您只有德语书籍,那么您会在 “406 - 不可接受”状态下给我一个空的回复。
406是服务器告诉您“我有您要求的内容,但您不会接受它们”。
这就是http请求中的Accept标头的用途。例如,如果HTTP请求包含仅接受“img / jpg”MIME类型的指示,则如果请求的文件是Excel电子表格,则服务器将发送406状态。
诊断:
“406不可接受”是一个不寻常的状态代码 - 最常见的是200,404,500,301。当服务器出现问题时,你只会看到406,通常是愚蠢但难以诊断的东西。
答案 1 :(得分:0)
我有同样的问题。我的问题是我正在发出HTML请求,但我的response_to块仅接受js。
所以我需要更改它:
respond_to do |format|
format.js
end
对此:
respond_to do |format|
format.html
format.js
end
然后所有这些再次起作用。