<commit_before>class LessonPlanMilestonesController < ApplicationController
  load_and_authorize_resource :course
  load_and_authorize_resource :lesson_plan_milestone, through: :course, except: [:create, :bulk_update]

  before_filter :load_general_course_data, :except => [:destroy]

  def show

  end

  def new

  end

  def create
    authorize! :create, LessonPlanMilestone
    raw_milestones = not(params[:lesson_plan_milestone]['0']) ?
      {'0' => params[:lesson_plan_milestone]} :
      params[:lesson_plan_milestone]
    milestones = []
    raw_milestones.each_pair do |key, value|
      milestone = LessonPlanMilestone.create
      milestone.course = @course
      milestone.attributes = value
      milestone.creator = current_user
      milestone.end_at = milestone.end_at.end_of_day if milestone.end_at
      milestones.push(milestone)
    end

    respond_to do |format|
      begin
        LessonPlanMilestone.transaction do
          milestones.each {|milestone|
            milestone.save!
          }
        end
      rescue Exception => e
        @lesson_plan_milestone = milestones[0]
        format.html { render action: "new" }
        format.json { render json: { status: 'Error', message: e.message, :status => 400 }}
      else
        path = course_lesson_plan_path(@course, :anchor => 'milestone-' + milestones[0].id.to_s)
        format.html {<commit_msg>Add start_at in milestone controller.<commit_after>class LessonPlanMilestonesController < ApplicationController
  load_and_authorize_resource :course
  load_and_authorize_resource :lesson_plan_milestone, through: :course, except: [:create, :bulk_update]

  before_filter :load_general_course_data, :except => [:destroy]

  def show

  end

  def new

  end

  def create
    authorize! :create, LessonPlanMilestone
    raw_milestones = not(params[:lesson_plan_milestone]['0']) ?
      {'0' => params[:lesson_plan_milestone]} :
      params[:lesson_plan_milestone]
    milestones = []
    raw_milestones.each_pair do |key, value|
      milestone = LessonPlanMilestone.create
      milestone.course = @course
      milestone.attributes = value
      milestone.creator = current_user
      milestone.start_at = milestone.start_at.beginning_of_day if milestone.start_at
      milestone.end_at = milestone.end_at.end_of_day if milestone.end_at
      milestones.push(milestone)
    end

    respond_to do |format|
      begin
        LessonPlanMilestone.transaction do
          milestones.each {|milestone|
            milestone.save!
          }
        end
      rescue Exception => e
        @lesson_plan_milestone = milestones[0]
        format.html { render action: "new" }
        format.json { render json: { status: 'Error', message: e.message, :status => 400 }}
      else
        path = course_lesson_plan_path(@course, :anchor => 'milestone-' + milestones[0].id.to_s)
        format.html {
{'fraction_non_alphanumeric': 0.09302325581395349, 'fraction_numerical': 0.004859423811176675, 'mean_word_length': 3.2072992700729928, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '130779', 'n_tokens_mistral': 919, 'n_tokens_neox': 875, 'n_words': 180}