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