阻止Rails 3.2渲染html.erb和js.erb

时间:2012-02-15 02:20:31

标签: javascript ruby-on-rails ajax

我正在对Home#index中的空操作调用HomeController操作。

页面在HTML中加载正常,这是我所期望的(渲染home/index.html.erb,但它也会为该操作加载相应的js,在渲染home/index.js.erb之后约100ms到达。我怎么能阻止这个呢?我只是想在我呼叫时响应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";

1 个答案:

答案 0 :(得分:0)

从控制器中的format.html块中删除respond_to