StudentController#populate:
def populate
# Process:
# 1. AJAX call made by jQuery to populate the student table
# 2. Find students from the database
# 3. Pass in the student data into the helper function (construct_table_rows defined in UsersHelper)
@students_data = Student.all(:order => 'user_name',
:include => [:section,
:grace_period_deductions])
# Function below contained within helpers/users_helper.rb
@students = construct_table_rows(@students_data)
respond_to do |format|
format.json { render :json => @students }
end
end
boot.js.erb called by students/index.html.erb:
jQuery.ajax({
url: "<%= populate_students_path() %>",
data: 'authenticity_token=' + AUTH_TOKEN,
type: "POST",
async: true,
dataType: 'json'
}).done(function (data) {
jQuery('#loading_list').hide();
console.log(data);
populate(data);
});