docbrown/app/controllers/admin/events_controller.rb
Ridhwana cf5207564f
RFC#50-P5 Prepares the admin restructure to be tested (#13114)
* feat: make the sidebar more dynamic

* refactor: use the action in the same controller instead of the whole path

* feat: remove hardcoded routes

* feat: move routes into file

* feat: use rails 6 draw for the admin routes

* add a helper method

* oops: fix super

* feat: add the hacky helper methods :( )

* WIP: created different path helpers for the new routes and point the old helpers to the new ones if the FF is toggled

* feat: update the module

* chore: add new paths

* feat: change link_to's use paths instead

* feat: feedback_messages to scoped admin route

* chore: update the feature flag urls helpers

* feat: feedback_messages issue

* chore: remove all the workarounds

* chore: rubucop

* fix: oops remove helper

* chore: comment out the tests that touch the tabbed navbar which is affected by the rails application needing to be reloaded

* feat: ensure that we chcek if the db table exists
2021-04-15 14:53:46 +02:00

55 lines
1.3 KiB
Ruby

module Admin
class EventsController < ApplicationController
layout "admin"
include ApplicationHelper
def index
@events = Event.order(starts_at: :desc).page(params[:page]).per(20)
end
def new
@event = Event.new(
location_name: "#{URL.domain}/live",
location_url: app_url,
description_markdown: "*Description* *Pre-requisites:* *Bio*",
)
end
def edit
@event = Event.find(params[:id])
end
def create
@event = Event.new(event_params)
if @event.save
flash[:success] = "Successfully created event: #{@event.title}"
redirect_to admin_events_path
else
flash[:danger] = @event.errors.full_messages
render :new
end
end
def update
@event = Event.find(params[:id])
if @event.update(event_params)
flash[:success] = "#{@event.title} was successfully updated"
redirect_to admin_events_path
else
flash[:danger] = @event.errors.full_messages
render :edit
end
end
private
def event_params
allowed_params = %i[
title category event_date starts_at ends_at
location_name cover_image location_url description_markdown published
host_name profile_image live_now
]
params.require(:event).permit(allowed_params)
end
end
end