Ostap Tan
Ostap Tan

Reputation: 111

Buttons don't make Ajax request but reload page Rails

I am very new with ajax with rails so here is the problem. I have method in controller :multi =>

respond_to do |format|
  format.js
end

The view for metod

<ul id="actions">
    <%= @game.user.actions %>
</ul>

<%= button_link_to "call", drid(:anchor => "opponents", :action => :call, :remote => true), :class => 'button' %>
<%= button_link_to "check", drid(:anchor => "opponents", :action => :check, :remote => true), :class => 'button' %>

@game.user.actions are in the database.

Here is ajax template

$("#actions").append("<%= escape_javascript @game.user.actions %>");
$("#new_action")[0].reset();

Problem is next: when I click on the buttons they add a new events to the list of actions (e.g. ["call", "call", "call", "call", "check", "call", "call", "check", "check", "check", "call", "call"]), but the page is still reloading without any asynchronus request.

Please help as you can! any answers would be helpful!

Upvotes: 0

Views: 176

Answers (1)

rt2800
rt2800

Reputation: 3045

call e.preventDefault(); in the JS click-handler for button

Upvotes: 1

Related Questions