docbrown/app/controllers/internal/events_controller.rb
Andy Zhao d6a7102f3b [Done] Fix update and create events (#404)
* Close out a div properly

* Rename file to .html.erb

* Move new event form back to index page

* Update test to use index view
2018-06-07 15:35:09 -04:00

56 lines
1.7 KiB
Ruby

module Internal
class EventsController < ApplicationController
layout "internal"
def index
@event = Event.new(
location_name: "dev.to/live",
location_url: "https://dev.to",
description_markdown: "*Description* *Pre-requisites:* *Bio*",
)
@events = Event.order("starts_at ASC")
end
def create
@event = Event.new(event_params)
@events = Event.order("starts_at ASC")
if @event.save
flash[:success] = "Successfully created event: #{@event.title}"
redirect_to(action: :index)
else
flash[:danger] = @event.errors.full_messages
render "index.html.erb"
end
end
def update
@event = Event.find(params[:id])
@events = Event.order("starts_at ASC")
if @event.update(event_params)
CacheBuster.new.bust "/live_articles"
flash[:success] = "#{@event.title} was successfully updated"
redirect_to "/internal/events"
else
flash[:danger] = @event.errors.full_messages
render "index.html.erb"
end
end
private
def event_params
params.require(:event).permit(:title,
:category,
:event_date,
:starts_at,
:ends_at,
:location_name,
:cover_image,
:location_url,
:description_markdown,
:published,
:host_name,
:profile_image,
:live_now)
end
end
end