<commit_before>class EventsController < ApplicationController
  #require 'delorean'

  before_action :authenticate_user!, except: [:index, :show]
  before_action :set_event, only: [:show, :edit, :update, :destroy, :update_only_url]

  def new
    @event = Event.new
  end

  def show
    @event_schedule = @event.current_occurences
    #puts @event_schedule
  end

  def index
    @events = []
    Event.all.each do |event|
      @events << event.current_occurences
    end
    @events = @events.flatten.sort_by { |e| e[:time] }
  end

  def edit
  end

  def create
    if params[:event][:event_date].empty?
      params[:event][:event_date] = Date.today
    end
    if params[:event][:start_time].empty?
      params[:event][:start_time] = Time.now
    end
    if params[:event][:end_time].empty?
      params[:event][:end_time] = Time.now + 30.minutes
    end
    @event = Event.new(event_params)
    if @event.save
      flash[:notice] = 'Event Created'
      redirect_to event_path(@event)
    else
      flash[:notice] = @event.errors.full_messages.to_sentence
      redirect_to new_event_path
    end
  end

  def update
    if @event.update_attributes(event_params)
      flash[:notice] = 'Event Updated'
      redirect_to events_path
    else
      flash[:alert] = ['Failed to update event:', @event.errors.full_messages].join(' ')
      redirect_to edit_event_path(@event)
    end
  end

  def update_only_url
    if @event.update_attributes(params[:event].permit(:url))
      flash[:notice] = 'Event URL has been updated'
    else
      flash[:alert] = 'You have to provide a valid hangout url'
    end
    redirect_to event_path(@event)
  end

  def destroy
    @event.destroy
    redirect_to events_path
  end

  private

  def set_event
    @event = Event.find(params[:id])
  end


  def event_params
    params.require(:event).permit!
  end


end<commit_msg>Added Friendly Id in Events Controller<commit_after>class EventsController < ApplicationController
  #require 'delorean'

  before_action :authenticate_user!, except: [:index, :show]
  before_action :set_event, only: [:show, :edit, :update, :destroy, :update_only_url]

  def new
    @event = Event.new
  end

  def show
    @event_schedule = @event.current_occurences
    #puts @event_schedule
  end

  def index
    @events = []
    Event.all.each do |event|
      @events << event.current_occurences
    end
    @events = @events.flatten.sort_by { |e| e[:time] }
  end

  def edit
  end

  def create
    if params[:event][:event_date].empty?
      params[:event][:event_date] = Date.today
    end
    if params[:event][:start_time].empty?
      params[:event][:start_time] = Time.now
    end
    if params[:event][:end_time].empty?
      params[:event][:end_time] = Time.now + 30.minutes
    end
    @event = Event.new(event_params)
    if @event.save
      flash[:notice] = 'Event Created'
      redirect_to event_path(@event)
    else
      flash[:notice] = @event.errors.full_messages.to_sentence
      redirect_to new_event_path
    end
  end

  def update
    if @event.update_attributes(event_params)
      flash[:notice] = 'Event Updated'
      redirect_to events_path
    else
      flash[:alert] = ['Failed to update event:', @event.errors.full_messages].join(' ')
      redirect_to edit_event_path(@event)
    end
  end

  def update_only_url
    if @event.update_attributes(params[:event].permit(:url))
      flash[:notice] = 'Event URL has been updated'
    else
      flash[:alert] = 'You have to provide a valid hangout url'
    end
    redirect_to event_path(@event)
  end

  def destroy
    @event.destroy
    redirect_to events_path
  end

  private

  def set_event
    @event = Event.friendly.find(params[:id])
  end


  def event_params
    params.require(:event).permit!
  end


end
{'fraction_non_alphanumeric': 0.11137566137566138, 'fraction_numerical': 0.0010582010582010583, 'mean_word_length': 3.1595159515951594, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2347265', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1220, 'n_words': 288}