![](/img/trans.png)
[英]How do I relocate the user to contents of another page without page refresh when navigating?
[英]Rails3: how do I do ajax-y updating? like, changing the contents of a page without having to refresh the page?
<li><%= link_to "Yes", { :controller => 'application', :action => 'start_game', :human_is_first => true }, :remote => true %></li>
在我的控制器中:
def start_game
respond_to do |format|
format.js
end
end
在start_game.js.erb中
$('.choose_options').fadeOut(1000);
调用start_game的我的erb:
<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)
您可以尝试使用request.xhr而不是使用response_to? 像这样:
if request.xhr?
render 'start_game.js.erb', :layout => false
end
科迪
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.