我有一个Heroku / Rails 3.2站点,主页位于欢迎/索引。所有的工作都很好,主页的点击量也很大,但是每隔一段时间,我就会注意到日志中的一个错误:
ActionView::MissingTemplate:缺少模板欢迎/索引,应用程序/索引与{:locale=>:en,:formats=>"image/*",:handlers=>:erb,:builder,:arb}。搜索到:*“/app/app/view”*“/app/ Searched /bundle/ruby/`.”(它列出了更多的宝石位置)
欢迎的观点在正常的地方,app/views/welcome/index.html.erb。formats=image/*对我来说是可疑的,如果我请求...com/welcome.jpg,我可能会导致类似的错误,但是日志将这些错误报告为根/的请求。
怎么一回事?我怎样才能阻止它?(我如何复制它?)
决议:
在控制器as shown in the accepted answer below中使用as shown in the accepted answer below。
解释:
我的应用程序试图响应各种类型的请求(html、jpg、json、rss等)。修复方法是只响应html请求,并向非html请求发送406个错误。我可以通过请求...com/welcome.rss之类的urls或在console中输入这些错误来复制这些错误:
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","",false);
xmlhttp.setRequestHeader("Accept", "image/*");
xmlhttp.send();修复的结果是:
发布于 2014-12-16 00:11:59
您可以在操作中添加respond_with以避免此错误。
例如,在users_contoller中:
respond_to :html
def index
@users = User.all
respond_with(@users)
end如果有/users.jpg的请求,它将返回不可接受的406 。
https://stackoverflow.com/questions/27495326
复制相似问题