Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 4-缺少模板/缺少部分错误,仅在生产中出现_Ruby On Rails_Ajax_Coffeescript_Partial Views_Content Type - Fatal编程技术网

Ruby on rails Rails 4-缺少模板/缺少部分错误,仅在生产中出现

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

我们刚刚用SSL证书保护了我们的应用程序。事实证明,使用HTTPS比我们想象的要复杂得多,我们目前正在整理一些由此产生的错误

我们在CoffeeScript中有一个AJAX调用,其中rails通过呈现部分脚本的html来响应。这在开发中非常有效

咖啡脚本:

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发行版。