[英]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.