开发者

Rails3: how do I do ajax-y updating? like, changing the contents of a page without having to refresh the page?

开发者 https://www.devze.com 2023-02-07 16:11 出处:网络
<li><%= link_to \"Yes\", { :controller => \'application\', :action => \'start_game\', :human_is_first => true}, :remote => true%></li>
<li><%= link_to "Yes", { :controller => 'application', :action => 'start_game', :human_is_first => true  }, :remote => true  %></li>

in my control开发者_StackOverflowler:

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

in start_game.js.erb

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

my erb that calls 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>

but when I click the link, the page redirects

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" 

Any help will be much appreciated.

(I'm using jQuery 1.4.3)


Rather than using respond_to, you might try using request.xhr? like so:

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

Cody

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号