[英]Rails 3.1 returns JS.erb as html
我有3.0,前一段时间我升级到了3.1。 我现在尝试在项目中添加一些Ajax,但是由于某种原因,尽管它看起来设置正确,并且该链接触发为远程链接,但返回的响应是html。
所以我将控制器设置为:
respond_to do |format|
format.js
end
在视图中:
%li=link_to comp.title, company_filter_path(comp.id), :remote=>true
但在萤火虫中,它返回的是这样的页面:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body id='home' lang='en'>
<section>
<!-- = content_tag :h1, yield(:title) if show_title? -->
alert("hello")
console.log(2)
</section>
</body>
</html>
我认为这可能是我在升级中错过的东西,但我看不到,有人有什么想法吗?
遇到相同问题的任何人都可以给我答案。
我在应用程序文件夹中定义布局,这迫使js渲染为模板。
将格式更改为:
respond_to do |format|
format.html { render "index"}
format.js{render :content_type=>'text/javascript',:layout=>false}
end
一切正常!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.