Ruby on rails Rails 4-缺少模板/缺少部分错误,仅在生产中出现
我们刚刚用SSL证书保护了我们的应用程序。事实证明,使用HTTPS比我们想象的要复杂得多,我们目前正在整理一些由此产生的错误 我们在CoffeeScript中有一个AJAX调用,其中rails通过呈现部分脚本的html来响应。这在开发中非常有效 咖啡脚本:Ruby on rails Rails 4-缺少模板/缺少部分错误,仅在生产中出现,ruby-on-rails,ajax,coffeescript,partial-views,content-type,Ruby On Rails,Ajax,Coffeescript,Partial Views,Content Type,我们刚刚用SSL证书保护了我们的应用程序。事实证明,使用HTTPS比我们想象的要复杂得多,我们目前正在整理一些由此产生的错误 我们在CoffeeScript中有一个AJAX调用,其中rails通过呈现部分脚本的html来响应。这在开发中非常有效 咖啡脚本: coffee_method: (pos, uid) => $.ajax '/contoller/test/', type: 'POST' data: pos: pos uid: uid
coffee_method: (pos, uid) =>
$.ajax '/contoller/test/',
type: 'POST'
data:
pos: pos
uid: uid
success: (data) ->
$('#result-div').html(data) #Populates side menu with _next_destination_menu content
error: ->
alert 'How embarassing! Something went wrong - please try your search again. '
控制器:
def test
... #do some stuff
puts "format requested: #{request.format}"
puts "format url_encodeded: #{request.format.url_encoded_form?}"
render partial: 'trips/_test' #app/views/trips/_test.html.erb
end
但是,在生产过程中,我们会遇到以下错误:
ActionView::MissingTemplate(缺少部分trips/\u测试,带有{:locale=>[:en],:formats=>[:url\u encoded\u form],:variants=>[],:handlers=>[:erb,:builder,:raw,:ruby,:coffee,:jbuilder]。
经过一番挖掘,我发现生产中的请求是一种不同的格式。使用控制器中的put
行进行调试,结果如下:
制作:
format requested: application/x-www-form-urlencoded
format url_encodeded: true
发展:
format requested: */*
format url_encodeded: false
处理此问题的最佳方法是什么。我是否:
- 更改CoffeeScript中每个AJAX调用的内容类型
- 将
添加到控制器respond\u to…format.url\u encoded\u form{render partial:trips/test}
format.all{…}
,但遇到了相同的问题。欢迎使用任何最佳做法
更新:
直接指定响应类型会导致相同的缺少模板错误:
respond_to do |format|
format.html {render partial: 'trips/test'}
format.json {render partial: 'trips/test' }
format.url_encoded_form {render partial: 'trips/test'}
end
更新2:
localhost和production的请求头是相同的,内容类型是application/x-www-form-urlencoded
,即使format.url\u encoded\u form?
返回false
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4
Connection:keep-alive
Content-Length:37
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
您可以尝试完全按照要求传递格式、区域设置和处理程序:
render(
partial: 'trips/test',
formats: [:html, :js, :json, :url_encoded_form],
locale: [:en],
handlers: [:erb, :builder, :raw, :ruby, :coffee, :jbuilder])
您是否使用可能会改变请求的代理(如nginx?)@NickTomlin-我不相信我们使用的是代理,但我们使用的是AWS CloudFront的web发行版。