Skip to content Skip to sidebar Skip to footer

Render A View In Rails Via Ajax And Controller

I have this JS code in my application.js: $(document).ready(function(){ var kraken_btc_eur_old = 0; setInterval(function(){ $.get('https://api.krake

Solution 1:

When you are sending a AJAX request, rails won't be able to update your view. That's because, as you said, you're not actually refreshing the page. So rails can't send the new HTML content to the browser.

In that case, you need to handle the logic of adding a new Bet in the frontend (Javascript).

Something like:

$.ajax({
  type: "POST",
  url: "/bets",
  data: { parameter: kraken_btc_eur_old },
  success: function (data) {
    var newBet = "<div>" + data.base_price + "</div>";
    $('list_of_bets').append(newBet);
  }
});

And on the rails side, you need to return the new Bet you just created as a JSON:

defcreate# your logic here 
  render json:@betend

Post a Comment for "Render A View In Rails Via Ajax And Controller"