Skip to content

Commit c1f4c50

Browse files
committed
added approved, rejected, and pending puzzles to view
1 parent 3a9ccbe commit c1f4c50

File tree

4 files changed

+137
-5
lines changed

4 files changed

+137
-5
lines changed

app/assets/stylesheets/application.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,34 @@ th, td {
2121
th {
2222
background-color: #f2f2f2;
2323
}
24+
.inline-form {
25+
display: inline;
26+
}
27+
.approve-btn {
28+
background-color: #4CAF50;
29+
color: white;
30+
border: none;
31+
padding: 6px 12px;
32+
margin-left: 4px;
33+
border-radius: 4px;
34+
cursor: pointer;
35+
}
36+
.reject-btn {
37+
background-color: #f44336;
38+
color: white;
39+
border: none;
40+
padding: 6px 12px;
41+
margin-left: 4px;
42+
border-radius: 4px;
43+
cursor: pointer;
44+
}
45+
46+
.pending-btn {
47+
background-color: yellow;
48+
color: black;
49+
border: none;
50+
padding: 6px 12px;
51+
margin-left: 4px;
52+
border-radius: 4px;
53+
cursor: pointer;
54+
}
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
class PuzzlesController < ApplicationController
22
def index
3-
@puzzles = Puzzle.all
3+
@pending_puzzles = Puzzle.pending
4+
@approved_puzzles = Puzzle.approved
5+
@rejected_puzzles = Puzzle.rejected
6+
end
7+
8+
def approve
9+
puzzle = Puzzle.find(params[:id])
10+
puzzle.update(state: :approved)
11+
redirect_to puzzles_path, notice: "Puzzle approved."
12+
end
13+
14+
def reject
15+
puzzle = Puzzle.find(params[:id])
16+
puzzle.update(state: :rejected)
17+
redirect_to puzzles_path, notice: "Puzzle rejected."
18+
end
19+
20+
def pending
21+
puzzle = Puzzle.find(params[:id])
22+
puzzle.update(state: :pending)
23+
redirect_to puzzles_path, notice: "Puzzle marked as pending."
424
end
525
end

app/views/puzzles/index.html.erb

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,101 @@
11
<% if session[:user_token] %>
22
<%= link_to 'Logout', session_path(1), data: { turbo_method: :delete } %>
3-
<h1>Puzzles</h1>
3+
<h1>Pending Puzzles</h1>
44
<table>
55
<thead>
66
<tr>
77
<th>Question</th>
88
<th>Answer</th>
99
<th>Explanation</th>
1010
<th>Link</th>
11+
<th>Actions</th>
1112
</tr>
1213
</thead>
1314
<tbody>
14-
<% @puzzles.each do |puzzle| %>
15+
<% @pending_puzzles.each do |puzzle| %>
1516
<tr>
1617
<td><%= puzzle.question %></td>
1718
<td><%= puzzle.answer %></td>
1819
<td><%= puzzle.explanation %></td>
19-
<td><%= link_to 'View', puzzle.link, target: '_blank' if puzzle.link.present? %></td>
20+
<td>
21+
<% if puzzle.link.present? %>
22+
<%= link_to 'View', puzzle.link, target: '_blank' %>
23+
&nbsp;
24+
<% end %>
25+
</td>
26+
<td>
27+
<%= button_to 'Approve', approve_puzzle_path(puzzle), method: :patch, form_class: 'inline-form', class: 'approve-btn' %>
28+
<%= button_to 'Reject', reject_puzzle_path(puzzle), method: :patch, form_class: 'inline-form', class: 'reject-btn' %>
29+
</td>
2030
</tr>
2131
<% end %>
2232
</tbody>
2333
</table>
34+
35+
<h1>Approved Puzzles</h1>
36+
<table>
37+
<thead>
38+
<tr>
39+
<th>Question</th>
40+
<th>Answer</th>
41+
<th>Explanation</th>
42+
<th>Link</th>
43+
<th>Actions</th>
44+
</tr>
45+
</thead>
46+
<tbody>
47+
<% @approved_puzzles.each do |puzzle| %>
48+
<tr>
49+
<td><%= puzzle.question %></td>
50+
<td><%= puzzle.answer %></td>
51+
<td><%= puzzle.explanation %></td>
52+
<td>
53+
<% if puzzle.link.present? %>
54+
<%= link_to 'View', puzzle.link, target: '_blank' %>
55+
&nbsp;
56+
<% end %>
57+
</td>
58+
<td>
59+
<%= button_to 'Reject', reject_puzzle_path(puzzle), method: :patch, form_class: 'inline-form', class: 'reject-btn' %>
60+
<%= button_to 'Pending', pending_puzzle_path(puzzle), method: :patch, form_class: 'inline-form', class: 'pending-btn' %>
61+
</td>
62+
</tr>
63+
<% end %>
64+
</tbody>
65+
</table>
66+
67+
<h1>Rejected Puzzles</h1>
68+
<table>
69+
<thead>
70+
<tr>
71+
<th>Question</th>
72+
<th>Answer</th>
73+
<th>Explanation</th>
74+
<th>Link</th>
75+
<th>Actions</th>
76+
</tr>
77+
</thead>
78+
<tbody>
79+
<% @rejected_puzzles.each do |puzzle| %>
80+
<tr>
81+
<td><%= puzzle.question %></td>
82+
<td><%= puzzle.answer %></td>
83+
<td><%= puzzle.explanation %></td>
84+
<td>
85+
<% if puzzle.link.present? %>
86+
<%= link_to 'View', puzzle.link, target: '_blank' %>
87+
&nbsp;
88+
<% end %>
89+
</td>
90+
<td>
91+
<%= button_to 'Approve', approve_puzzle_path(puzzle), method: :patch, form_class: 'inline-form', class: 'approve-btn' %>
92+
<%= button_to 'Pending', pending_puzzle_path(puzzle), method: :patch, form_class: 'inline-form', class: 'pending-btn' %>
93+
</td>
94+
</tr>
95+
<% end %>
96+
</tbody>
97+
</table>
98+
2499
<% else %>
25100
<%= link_to 'Login with Google', '/auth/google_oauth2' %>
26101
<% end %>

config/routes.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Rails.application.routes.draw do
2-
resources :puzzles, only: [:index]
2+
resources :puzzles, only: [:index] do
3+
member do
4+
patch :approve
5+
patch :reject
6+
patch :pending
7+
end
8+
end
39
resources :sessions, only: [:create, :destroy]
410

511
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

0 commit comments

Comments
 (0)