[英]Stop Rails 3.2 from rendering both html.erb and js.erb
我在HomeController
中將一個動作Home#index
HomeController
稱為空動作。
頁面在HTML中加載很好,這是我所期望的(渲染home/index.html.erb
,但它也會為該操作加載相應的js,到達100ms后(渲染home/index.js.erb
)我怎么能阻止這個呢?我只想在我調用它時得到javascript響應,而不是通過HTTP GET請求。
HomeController的
class HomeController < ApplicationController
respond_to :html, :js # Nothing changes whether I have this or not
def index
respond_to do |format| # Nothing changes whether I have this or not
format.html
format.js
end
end
end
的routes.rb
Ajaxtest::Application.routes.draw do
get "home/index"
root to: 'home#index'
end
index.html.erb
<p>Find me in app/views/home/index.html.erb.</p>
index.js.erb的
$("#content").html("Lorem ipsum dolor sit amet, yo non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
document.title = "AJAX loaded";
從控制器的respond_to
塊中刪除format.html
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.