Skip to content

Commit 4ca7b7e

Browse files
committed
list puzzles on index page
1 parent 94a239a commit 4ca7b7e

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

app/models/puzzle.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class Puzzle < ApplicationRecord
22
enum :answer, ruby: 0, rails: 1
3+
enum :state, { approved: 0, rejected: 1, pending: 2 }
34
has_many :answers
45
end

app/views/puzzles/index.html.erb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
<% if session[:user_token] %>
22
<%= link_to 'Logout', session_path(1), data: { turbo_method: :delete } %>
33
<h1>Puzzles#index</h1>
4-
<p>Find me in app/views/puzzles/index.html.erb</p>
4+
<table>
5+
<thead>
6+
<tr>
7+
<th>Question</th>
8+
<th>Answer</th>
9+
<th>Explanation</th>
10+
<th>Link</th>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
<% @puzzles.each do |puzzle| %>
15+
<tr>
16+
<td><%= puzzle.question %></td>
17+
<td><%= puzzle.answer %></td>
18+
<td><%= puzzle.explanation %></td>
19+
<td><%= link_to 'View', puzzle.link, target: '_blank' if puzzle.link.present? %></td>
20+
</tr>
21+
<% end %>
22+
</tbody>
23+
</table>
524
<% else %>
625
<%= link_to 'Login with Google', '/auth/google_oauth2' %>
726
<% end %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddStateToPuzzles < ActiveRecord::Migration[8.0]
2+
def change
3+
add_column :puzzles, :state, :integer, default: 2, null: false
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)