Browse Source

Simplified setup to get or create @event

remotes/origin/master
echarp 2 years ago
parent
commit
25f7f1cc0c
  1. 16
      app/controllers/events_controller.rb

16
app/controllers/events_controller.rb

@ -6,8 +6,8 @@ class EventsController < ApplicationController
has_scope :future, type: :boolean, default: true, only: [:index], if: :future?
before_action :set_events, only: :index
before_action :set_event, except: %i[index new preview_create create]
before_action :set_create_event, only: %i[new preview_create create]
before_action :new_event, unless: -> { params[:id].present? }
before_action :set_event, if: -> { params[:id].present? }
before_action :check_secret, only: %i[edit preview update destroy]
rescue_from ActiveRecord::StaleObjectError, with: :locked
@ -89,12 +89,7 @@ class EventsController < ApplicationController
@events = @events.includes :region if params[:format].present?
end
# Use callbacks to share common setup or constraints between actions
def set_event
@event = Event.find params[:id]
end
def set_create_event
def new_event
time = Time.zone.now.change(min: 0) + 1.day
params[:event] ||= {
start_time: time,
@ -104,6 +99,11 @@ class EventsController < ApplicationController
@event = Event.new event_params
end
# Use callbacks to share common setup or constraints between actions
def set_event
@event = Event.find params[:id]
end
# Never trust parameters from the scary internet, only allow the white list
# through
def event_params

Loading…
Cancel
Save