2012-02-15 7 views
3

私はアクションHome#indexを空のアクションHomeControllerに呼び出しています。Rails 3.2がhtml.erbとjs.erbのレンダリングを停止する

ページがHTMLで正常に読み込まれます(レンダリングhome/index.html.erbですが、そのアクションの対応するjsもロードされ、100ms後に到着します(レンダリングhome/index.js.erb)。私がいないHTTP GETリクエストによって、それを呼び出したときにのみjavascriptの応答をしたい。

に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"; 

答えて

0

コントローラでrespond_toブロックからformat.htmlを削除。

+0

これを行うと、HTTP GETリクエストを介してhtmlに応答しなくなります。しかし、提案をありがとう! – joseph

関連する問題