-
Notifications
You must be signed in to change notification settings - Fork 0
/
events_controller.rb
63 lines (53 loc) · 1.45 KB
/
events_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class EventsController < ApplicationController
before_action :set_event, only: %i[ show edit update destroy ]
def index
@events = Event.order(start_date: :desc)
end
def show
end
def new
@event = Event.new
end
def edit
end
def create
@event = Event.new(event_params)
respond_to do |format|
if @event.save
format.html { redirect_to event_url(@event), notice: "Event was successfully created." }
else
format.html { render :new, status: :unprocessable_entity }
end
end
end
def update
if params[:like].present?
@event.increment!(:likes_count)
# @events = Event.order(start_date: :desc)
# return
Turbo::StreamsChannel.broadcast_refresh_to "events_broadcaster"
return redirect_to events_path
end
respond_to do |format|
if @event.update(event_params)
format.html { redirect_to event_url(@event), notice: "Event was successfully updated." }
else
format.html { render :edit, status: :unprocessable_entity }
end
end
end
def destroy
@event.destroy!
Turbo::StreamsChannel.broadcast_refresh_to "events_broadcaster"
respond_to do |format|
format.html { redirect_to events_url, notice: "Event was successfully destroyed." }
end
end
private
def set_event
@event = Event.find(params[:id])
end
def event_params
params.require(:event).permit(:name, :location, :start_date)
end
end