[英]Stop Rails 3.2 from rendering both html.erb and js.erb
I'm calling an action, Home#index
, to an empty action in HomeController
. 我在
HomeController
中将一个动作Home#index
HomeController
称为空动作。
The page loads fine in HTML, which is what I expect (rendering home/index.html.erb
, but then it also loads the corresponding js for that action as well, arriving some 100ms after (rendering home/index.js.erb
). How can I stop this? I only want the javascript response when I call for it, not through an HTTP GET request. 页面在HTML中加载很好,这是我所期望的(渲染
home/index.html.erb
,但它也会为该操作加载相应的js,到达100ms后(渲染home/index.js.erb
)我怎么能阻止这个呢?我只想在我调用它时得到javascript响应,而不是通过HTTP GET请求。
HomeController 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 的routes.rb
Ajaxtest::Application.routes.draw do
get "home/index"
root to: 'home#index'
end
index.html.erb index.html.erb
<p>Find me in app/views/home/index.html.erb.</p>
index.js.erb 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.