簡體   English   中英

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

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM