hubfeenix.fi/app/controllers/events_controller.rb
2023-01-22 20:40:28 +02:00

61 lines
1.4 KiB
Ruby

class EventsController < ApplicationController
before_action :set_event, only: %i[ show edit update destroy ]
def index
@events = Event.all
end
def show
end
def new
kind = params[:profile]
kind = Profile.kinds.first unless Profile.kinds.include?(kind)
profile = current_member.profile(kind)
if(profile)
@event = Event.new profile: profile
else
redirect_to member_path(current_member), notice: "No such profile #{kind}."
end
end
def edit
end
def create
@event = Event.new(event_params)
if @event.save
redirect_to @event, notice: "Event was successfully created."
else
render :new, status: :unprocessable_entity
end
end
def update
if @event.update(event_params)
redirect_to @event, notice: "Event was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end
# DELETE /events/1
def destroy
@event.destroy
redirect_to events_url, notice: "Event was successfully destroyed."
end
private
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find(params[:id])
end
# Only allow a list of trusted parameters through.
def event_params
params.require(:event).permit(:name, :text, :start_date, :end_date,
:profile_id, :picture, :picture_cache)
end
end