Rails respond_to 格式 - 需要 .js 扩展名吗?
我正在捕获链接单击事件并通过 ajax(特别是 jquery 的 getScript)转发它们。
在开发中,在响应格式方面一切正常。
respond_to do |format|
format.html {
#by default renders show.html.haml
}
format.js {
#by default renders show.js.erb
}
end
这种行为在heroku上的生产中不会发生,并且始终返回html文件。如果我添加文件扩展名并为路径定义格式识别,那么这可以正常工作,但是我认为这没有必要?
提前致谢。
I am capturing link click events and forwarding them via ajax, specifically jquery's getScript.
In development everything works fine with regard to respond to format
respond_to do |format|
format.html {
#by default renders show.html.haml
}
format.js {
#by default renders show.js.erb
}
end
This behaviour somehow isn't taking place in production on heroku and the html file is always returned. If I add the file extension and define format recognition to the route then this works ok, however I thought this wasn't necessary?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人遇到这个问题,我会解释我做错了什么。
我正在利用 Heroku 的 varnish 实现来加速应用程序。发生的情况是从 varnish 下载先前生成的动态网页,然后 javascript 调用相同的 url 来检查页面更新。这大大缩短了页面响应时间,但代价是非 js 用户和搜索引擎可能会查看稍微陈旧的内容。
看起来清漆不区分接受标头,并且我返回了之前缓存的 html。为了解决这个问题,我只是在 ajax 请求中添加了一个时间戳参数。
If anyone comes across this I'll explain what I was doing wrong.
I'm making use of heroku's implementation of varnish to speed up an application. What happens is a previously generated dynamic webpage is downloaded from varnish then javascript calls home to the same url to check for page updates. This improves page response times considerably at the expense of non-js users and search engines potentially viewing slightly stale content.
It appears varnish doesn't distinguish between accepts headers and I was returned the previously cached html. To resolve this I've simply added a time stamp param to the ajax request.