我在rails应用程序中设置了异常通知程序。所以今天我收到了第二个通知,即index
模板丢失了:
An ActionView::MissingTemplate occurred in products#index:
Missing template products/index, application/index with {:locale=>[:en, :de], :formats=>["text/html;text/plain"], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :slim, :arb, :jbuilder]}. Searched in:
* "/home/releases/20160518143810/app/views"
-------------------------------
Request:
-------------------------------
* URL : http://example.com/shop
* HTTP Method: GET
* IP address : xx.xx.xx.xx
* Parameters : {"controller"=>"products", "action"=>"index"}
* Timestamp : 2016-06-07 08:19:13 +0200
* Server : vintage-shop.ch
* Rails root : /home/releases/20160518143810
* Process: 15714
我知道一个事实,产品的索引模板在服务器上并在VCS中签入,应用程序已经运行了一个月。所以我真的很想知道为什么会发生这种情况:
$ ls /home/releases/20160518143810/app/views/products/index.html.slim
# -> /home/releases/20160518143810/app/views/products/index.html.slim
这个例外怎么可能?
更新:我查找了IP地址,而不是来自我希望客户来自的地区。所以我想知道这是否是某种攻击,但问题仍然是如何触发异常,即使模板存在。
答案 0 :(得分:1)
这可能是攻击尝试或(更可能是我猜)某些随机噪音。问题似乎是在Rails从请求标头中解析出来的格式。通常,您应该在异常消息中看到类似:formats=>[:html, :text, :js, :css, :ics]
的内容。
通常使用请求URI(通常在点'.'
之后的所有内容都被视为格式规范)或使用Accept
标头在rails中确定格式。在你的情况下,它是我猜的标题(你应该能够在异常通知中看到标题)。 Accept
标题应包含 逗号分隔的 内容类型,而不是分号 - 分隔,所以我猜这是实际的来源例外。
如果您想了解有关Rails格式解析的更多详细信息,请查看此insightful blog post。