Skip to content

Instantly share code, notes, and snippets.

@ghigt
Created July 19, 2013 11:42
Show Gist options
  • Save ghigt/6038564 to your computer and use it in GitHub Desktop.
Save ghigt/6038564 to your computer and use it in GitHub Desktop.
Problem jquery

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);
        });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment