<commit_before>class EventsController < ApplicationController
  before_action :set_event, only: [:show, :edit, :update, :destroy]
  autocomplete :user, :full_name, full: true

  # GET /events
  # GET /events.json
  def index
    @events = Invite.where(user: current_user).map(&:event) || []
  end

  def attendance
    @event = Event.find(params[:event_id])
    @group = @event.group
    @rsvps = @event.invites.where(rsvp: true)
  end

  # GET /events/1
  # GET /events/1.json
  def show
    @post = Post.new
    @reply = Reply.new
    @event = Event.find(params[:id])
    @event_id = @event.id
    @group = @event.group
    @posts = @event.posts.where(group_id: nil)
    @group_id = nil
  end

  # GET /events/new
  def new
    if params.key?(:event_param)
      @event = Event.new(params[:event_param].permit(:title, :description, :starttime,
                                                     :startdate, :endtime, :enddate, :location))
    else
      @event = Event.new
    end
    @group = Group.friendly.find(params[:group_id])
    @users = @group.users.where.not(id: current_user.id).decorate.map { |u| [u.full_name, u.id] }
  end

  # POST /events
  # POST /events.json
  def create
    @event = Event.new(event_params)
    if(not params[:gmap].nil?)
      @event.gmap = true
    end
    @group = Group.friendly.find(params[:group_id])
    @event.group = @group
    if @event.save
      @event.add_users(current_user, organizers = params[:selected_organizers].split(",").map{ |o| o.to_i })
      redirect_to group_event_path(@group, @event), notice: "Event was successfully created."
    else
      redirect_to action: "new", event_param: event_params
    end
  end

  # GET /events/1/edit
  def edit
    @event = Event.find(params[:id])
  end

  # PATCH/PUT /events/1
  # PATCH/PUT /events/1.json
  def update
    @event = Event.find(params[:id])
    if @event.update_attributes(event_params)
      @event.update_organizers(current_user, organizers = params[:selected_organizers].split(",").map{ |o| o.to_i })
      flash[:notice] = "Event updated!"
      redirect_to group_event_path
    else
      flash[:alert] = "unable to update event: " + e.errors 
      redirect_to :back
    end
  end

  # DELETE /events/1
  # DELETE /events/1.json
  def destroy
    @event = Event.find(params[:id])
    @group = @event.group_id
    @event.send_cancel
    @event.destroy
    respond_to do |format|
      format.html { redirect_to group_path(@group), notice: "Event was successfully deleted." }
      format.json { head :no_content }
    end<commit_msg>small error in events controller<commit_after>class EventsController < ApplicationController
  before_action :set_event, only: [:show, :edit, :update, :destroy]
  autocomplete :user, :full_name, full: true

  # GET /events
  # GET /events.json
  def index
    @events = Invite.where(user: current_user).map(&:event) || []
  end

  def attendance
    @event = Event.find(params[:event_id])
    @group = @event.group
    @rsvps = @event.invites.where(rsvp: true)
  end

  # GET /events/1
  # GET /events/1.json
  def show
    @post = Post.new
    @reply = Reply.new
    @event = Event.find(params[:id])
    @event_id = @event.id
    @group = @event.group
    @posts = @event.posts.where(group_id: nil)
    @group_id = nil
  end

  # GET /events/new
  def new
    if params.key?(:event_param)
      @event = Event.new(params[:event_param].permit(:title, :description, :starttime,
                                                     :startdate, :endtime, :enddate, :location))
    else
      @event = Event.new
    end
    @group = Group.friendly.find(params[:group_id])
    @users = @group.users.where.not(id: current_user.id).decorate.map { |u| [u.full_name, u.id] }
  end

  # POST /events
  # POST /events.json
  def create
    @event = Event.new(event_params)
    if(not params[:gmap].nil?)
      @event.gmap = true
    end
    @group = Group.friendly.find(params[:group_id])
    @event.group = @group
    if @event.save
      @event.add_users(current_user, organizers = params[:selected_organizers].split(",").map{ |o| o.to_i })
      redirect_to group_event_path(@group, @event), notice: "Event was successfully created."
    else
      redirect_to action: "new", event_param: event_params
    end
  end

  # GET /events/1/edit
  def edit
    @event = Event.find(params[:id])
  end

  # PATCH/PUT /events/1
  # PATCH/PUT /events/1.json
  def update
    @event = Event.find(params[:id])
    if @event.update_attributes(event_params)
      @event.update_organizers(current_user, organizers = params[:selected_organizers].split(",").map{ |o| o.to_i })
      flash[:notice] = "Event updated!"
      redirect_to group_event_path
    else
      flash[:alert] = "unable to update event: " + @event.errors 
      redirect_to :back
    end
  end

  # DELETE /events/1
  # DELETE /events/1.json
  def destroy
    @event = Event.find(params[:id])
    @group = @event.group_id
    @event.send_cancel
    @event.destroy
    respond_to do |format|
      format.html { redirect_to group_path(@group), notice: "Event was successfully deleted." }
      format.json { head :no_content }
    end
{'fraction_non_alphanumeric': 0.13531931464174454, 'fraction_numerical': 0.0027258566978193145, 'mean_word_length': 2.8769811320754717, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3612144', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1717, 'n_words': 381}