<commit_before>class EventsController < ApplicationController
  load_resource except: :create
  authorize_resource
  layout 'application'

  rescue_from FbGraph::InvalidRequest, with: :event_doesnt_exist

  def index
    @events = Event.where user: current_user
  end

  def show
    @event = FbGraph::Event.new(@event.id).fetch(access_token: Token.app_token)
  end

  def new
    @event = Event.new
  end

  def destroy
    @event.destroy
    flash[:success] = t '.destroy/success'
    redirect_to Event
  end

  def create
    @event = Event.new event_params
    if @event.save
      redirect_to @event
    else
      flash[:danger] = t '.create.failure'
      render :new
    end
  end

  def edit
  end

  def update
    if @event.update event_params
      flash[:success] = t '.update/success'
      redirect_to @event
    else
      flash[:success] = t '.update/failure'
      render :edit
    end
  end

  private

  def event_doesnt_exist exception
    if exception.error_code == 100
      @event.delete
      flash[:error] = t '.event_doesnt_exist'
      redirect_to Event
    else
      throw exception
    end
  end

  def event_params
    params[:event][:user_id] = current_user.id
    params.require(:event).permit(
      :name,
      :start_date,
      :description,
      :location,
      :start_time,<commit_msg>Fixed some incorrect locale references in events<commit_after>class EventsController < ApplicationController
  load_resource except: :create
  authorize_resource
  layout 'application'

  rescue_from FbGraph::InvalidRequest, with: :event_doesnt_exist

  def index
    @events = Event.where user: current_user
  end

  def show
    @event = FbGraph::Event.new(@event.id).fetch(access_token: Token.app_token)
  end

  def new
    @event = Event.new
  end

  def destroy
    @event.destroy
    flash[:success] = t '.destroy.success'
    redirect_to Event
  end

  def create
    @event = Event.new event_params
    if @event.save
      flash[:danger] = t '.create.success'
      redirect_to @event
    else
      flash[:danger] = t '.create.failure'
      render :new
    end
  end

  def edit
  end

  def update
    if @event.update event_params
      flash[:success] = t '.update.success'
      redirect_to @event
    else
      flash[:success] = t '.update.failure'
      render :edit
    end
  end

  private

  def event_doesnt_exist exception
    if exception.error_code == 100
      @event.delete
      flash[:error] = t '.event_doesnt_exist'
      redirect_to Event
    else
      throw exception
    end
  end

  def event_params
    params[:event][:user_id] = current_user.id
    params.require(:event).permit(
      :name,
      :start_date,
      :description,
      :location,
      :start_time,
{'fraction_non_alphanumeric': 0.08705193855157278, 'fraction_numerical': 0.0021945866861741038, 'mean_word_length': 2.6613119143239623, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2474515', 'n_tokens_mistral': 871, 'n_tokens_neox': 841, 'n_words': 220}