-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathlikes_controller.rb
More file actions
78 lines (65 loc) · 2.04 KB
/
likes_controller.rb
File metadata and controls
78 lines (65 loc) · 2.04 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class LikesController < ApplicationController
before_action :set_like, only: %i[ show edit update destroy ]
before_action :is_authorized, only: [:destroy, :create]
after_action :verify_authorized, except: [:home]
def is_authorized
if !@like.owner.private? || current_user.leaders.include?(@like.owner)|| @like.owner ==current_user
redirect_back(fallback_location: root_url, alert: "not authorized")
end
# GET /likes or /likes.json
def index
@likes = Like.all
end
# GET /likes/1 or /likes/1.json
def show
end
# GET /likes/new
def new
@like = Like.new
end
# GET /likes/1/edit
def edit
end
# POST /likes or /likes.json
def create
@like = Like.new(like_params)
respond_to do |format|
if @like.save
format.html { redirect_to @like, notice: "Like was successfully created." }
format.json { render :show, status: :created, location: @like }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @like.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /likes/1 or /likes/1.json
def update
respond_to do |format|
if @like.update(like_params)
format.html { redirect_to @like, notice: "Like was successfully updated." }
format.json { render :show, status: :ok, location: @like }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @like.errors, status: :unprocessable_entity }
end
end
end
# DELETE /likes/1 or /likes/1.json
def destroy
@like.destroy
respond_to do |format|
format.html { redirect_to likes_url, notice: "Like was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_like
@like = Like.find(params[:id])
end
# Only allow a list of trusted parameters through.
def like_params
params.require(:like).permit(:fan_id, :photo_id)
end
end