0

I need to make it so on my webpage the gets the value of the user's balance live. Right now I have the following code to get the value of the user's balance: <%=current_user.balance%>. The only problem is that it won't update live or close to live (every 5s or so). How can I make it so that the balance can update on the webpage live.

I have read that I should use AJAX, but I am not a pro and therefore do not know exactly how I should proceed.

Thank you. Let me know if I wasn't clear enough.

Pabi
  • 946
  • 3
  • 16
  • 47

1 Answers1

1

Based on the comment I made I think I know what you need. Give the balance an ID and whenever the time component is doing its thing add:

$('#balance_id').remove();
$('selector_of_parent').append('<%= j current_user.balance %>');

That should take care of it. The j is short for escape_javascript and is needed for using embedded ruby.

Edit* OR (just realized this might be better)

$('#balance_id').val('<%= j current_user.balance %>');
user1943992
  • 222
  • 3
  • 11