2011-01-27 40 views
0
<li><%= link_to "Yes", { :controller => 'application', :action => 'start_game', :human_is_first => true }, :remote => true %></li> 
在我的控制器

Rails3:我該如何做ajax-y更新?比如,更改頁面的內容而不必刷新頁面?

def start_game 
    respond_to do |format| 
     format.js 
    end 
    end 

在start_game.js.erb

$('.choose_options').fadeOut(1000); 

我ERB調用start_game:

<div class="welcome"> 
    Hello! 

    <div class="choose_turn"> 
    Would you like to go first? 

    <ul class="choose_options"> 
     <li><%= link_to "Yes", { :controller => 'application', :action => 'start_game', :human_is_first => true }, :remote => true %></li> 
     <li><%= link_to "No", { :controller => 'application', :action => 'start_game', :human_is_first => true }, :remote => false %></li> 
    </ul> 
    </div> 
</div> 

但是當我點擊鏈接時,頁面重定向

Template is missing 

Missing template application/start_game with {:locale=>[:en, :en], :handlers=>[:builder, :rjs, :rhtml, :rxml, :erb], :formats=>[:html]} in view paths "~/Documents/Aptana Studio 3 Workspace/tic-tac-toe-ai/tic-tac-toe-ai/app/views" 

任何幫助將不勝感激。

(我使用jQuery 1.4.3)

回答

1

而不是使用的respond_to,你可以嘗試使用request.xhr?像這樣:

if request.xhr? 
    render 'start_game.js.erb', :layout => false 
end 

科迪

+0

我得到這個錯誤: – NullVoxPopuli 2011-01-27 18:55:22

相關問題