Javascript Rails 3.1将JS.erb返回为html
我有3.0版本,我不久前升级到了3.1版本。我现在尝试在项目中添加一些ajax,但由于某种原因,虽然它看起来设置正确,并且链接作为远程链接激发,但它返回的响应是html 因此,我将控制器设置为:Javascript Rails 3.1将JS.erb返回为html,javascript,ruby,ruby-on-rails-3.1,Javascript,Ruby,Ruby On Rails 3.1,我有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 但在firebug中,它返回的页面如下: <!DOCTYPE h
respond_to do |format|
format.js
end
他认为:
%li=link_to comp.title, company_filter_path(comp.id), :remote=>true
但在firebug中,它返回的页面如下:
<!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>
测试
警报(“你好”)
控制台日志(2)
我想这可能是我在升级过程中遗漏了什么,但我看不出是什么,有人有什么想法吗?一位朋友给了我一个答案,回答了所有面临同样问题的人 我在应用程序文件夹中定义布局,这迫使js以模板的形式呈现 将格式更改为:
respond_to do |format|
format.html { render "index"}
format.js{render :content_type=>'text/javascript',:layout=>false}
end
一切都很完美