gpt4 book ai didi

ruby-on-rails - Rails *Completed 406 Not Acceptable"在生产中..在暂存中工作

转载 作者:行者123 更新时间:2023-12-04 06:16:54 24 4
gpt4 key购买 nike

我在生产服务器中遇到错误“Completed 406 Not Acceptable”,而我在暂存服务器中没有遇到该错误。

相同的代码在暂存中运行良好,但在生产中运行不正常。两个环境都安装了相同的 gem。我使用的是 Rails 版本 3.0.10。

在我的生产环境中,GET 请求作为 html 处理,但在暂存中它作为 js 处理。我只为 js 格式定义了 respond_to block 。我不确定为什么它在两种环境中表现不同。

我也尝试在 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"}

Controller :

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

这让我很生气。感谢你的帮助。

路线.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

`

最佳答案

经过大量调试终于得到了解决方案..

当服务器返回 Javascript 响应时,我的请求接受 header 需要 HTML,因此浏览器无法接受。

在我的例子中,一个 Javascript 文件在 application.html.erb 中缺少 javascript_include_tag。缺少的 Javascript 是 jquery_ujs.js。基本上这会设置接受 header ajax加载。包含在这个标签中的Javascripts将被缓存和存储。所以我添加了缺少的 Javascript 并删除了缓存的文件夹和 YIPPEE,我的问题得到了解决。

我将举一个我从某个博客上学到的小例子。看来对其他人理解406错误会有帮助。

406错误可以理解为: 假设我向你要了一本书要读,但我只能读英文和法文的书。如果您只有德语书籍,您会给我一个空洞的回复,状态为“406 - Not Acceptable ”。

406 是服务器告诉你“我有你要的东西,但你不会接受”。

这就是 http 请求中的 Accept header 的用途。例如,如果 HTTP 请求包含仅接受“img/jpg”MIME 类型的指示,如果请求的文件是 Excel 电子表格,服务器将发送 406 状态。

诊断:

  • 请求其中一个页面并分析 http 请求 header
  • 注意响应的 MIME 类型、字符集、GZIP 编码*

“406 Not Acceptable ”是一种不常见的状态代码 - 最常见的是 200、404、500、301。当服务器出现问题时,您只会看到 406,通常是一些愚蠢但难以诊断的问题。

关于ruby-on-rails - Rails *Completed 406 Not Acceptable"在生产中..在暂存中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18236649/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com