I have several spinners on my page after database table names. Using jQuery on document ready, I want to replace those spinners with a count of the number of records in the individually listed table names.
For example, below, imagine the asterisk is a spinner:
Client Orders *
changes to:
Client Orders (125)
- I already know how to get the table record count.
- I don't know exactly how to call from jQuery to Rails, passing the table name as a parameter, to get the count.
- Do I create a .js.erb partial?
- Do I just reference a helper method which returns the generated html?
- What is the best practice?
How would my jQuery code look in document ready?
<script type="text/javascript">
$(document).ready(function() {
$('#spinner1').html(/* ??? */);
$('#spinner2').html(/* ??? */);
$('#spinner3').html(/* ??? */);
});
</script>
EDIT: Okay, let me word this differently... I have a helper function which accepts a table_name argument, and returns the output html . How do I call that function so that it runs after the page has loaded?
- Can I call it in document.ready via jQuery?
- Or, do I need an .js.erb partial view?
- Or, am I missing something entirely?