summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDavid Gay <eapoems@riseup.net>2023-10-30 02:00:16 -0400
committerDavid Gay <eapoems@riseup.net>2023-10-30 02:03:52 -0400
commit13df3e5aadae04b322bff4cb0279b299e2c92a41 (patch)
treeb5d586ac7ce2d0e748012cc3bb16ec18976a302c /app
parent818a106338b6924024809698915b1114bbc202d7 (diff)
Start and view runs
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb1
-rw-r--r--app/controllers/home_controller.rb2
-rw-r--r--app/controllers/runs_controller.rb29
-rw-r--r--app/helpers/run_helper.rb2
-rw-r--r--app/models/checkpoint.rb2
-rw-r--r--app/models/game.rb2
-rw-r--r--app/models/run.rb2
-rw-r--r--app/views/layouts/application.html.erb2
-rw-r--r--app/views/runs/new.html.erb31
-rw-r--r--app/views/runs/show.html.erb4
10 files changed, 74 insertions, 3 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 09705d1..6b4dcfa 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,2 +1,3 @@
class ApplicationController < ActionController::Base
+ before_action :authenticate_user!
end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 6d3fe90..44156ce 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,3 +1,5 @@
class HomeController < ApplicationController
+ skip_before_action :authenticate_user!
+
def index; end
end
diff --git a/app/controllers/runs_controller.rb b/app/controllers/runs_controller.rb
new file mode 100644
index 0000000..303c0e3
--- /dev/null
+++ b/app/controllers/runs_controller.rb
@@ -0,0 +1,29 @@
+class RunsController < ApplicationController
+ def index
+ @runs = Run.all
+ end
+
+ def show
+ @run = Run.find(params[:id])
+ end
+
+ def new
+ @run = Run.new
+ end
+
+ def create
+ @run = Run.new(run_params)
+ @run.user = current_user
+ if @run.save
+ redirect_to run_path(@run), notice: "Created runs."
+ else
+ render :new, status: :unprocessable_entity
+ end
+ end
+
+protected
+
+ def run_params
+ params.require(:run).permit(:title, :description, :game_id)
+ end
+end
diff --git a/app/helpers/run_helper.rb b/app/helpers/run_helper.rb
new file mode 100644
index 0000000..1e2a3a7
--- /dev/null
+++ b/app/helpers/run_helper.rb
@@ -0,0 +1,2 @@
+module RunHelper
+end
diff --git a/app/models/checkpoint.rb b/app/models/checkpoint.rb
index 2a89128..c014b2e 100644
--- a/app/models/checkpoint.rb
+++ b/app/models/checkpoint.rb
@@ -1,4 +1,6 @@
class Checkpoint < ApplicationRecord
belongs_to :run
belongs_to :user
+
+ has_one_attached :save_file
end
diff --git a/app/models/game.rb b/app/models/game.rb
index bdf72ba..9da939f 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -1,5 +1,5 @@
class Game < ApplicationRecord
has_many :runs, dependent: :restrict_with_error
- validate :presence, [:title]
+ validates_presence_of :title
end
diff --git a/app/models/run.rb b/app/models/run.rb
index 91090b4..7c9209e 100644
--- a/app/models/run.rb
+++ b/app/models/run.rb
@@ -3,5 +3,5 @@ class Run < ApplicationRecord
belongs_to :user
has_many :checkpoints, dependent: :destroy
- validate :presence, [:title]
+ validates_presence_of :title
end
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index abe5895..46b1f5b 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -12,7 +12,7 @@
</head>
<body>
- <main class="container mx-auto mt-28 px-5 flex">
+ <main class="container mx-auto mt-28 px-5">
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
diff --git a/app/views/runs/new.html.erb b/app/views/runs/new.html.erb
new file mode 100644
index 0000000..e8b7b6e
--- /dev/null
+++ b/app/views/runs/new.html.erb
@@ -0,0 +1,31 @@
+<%= form_with model: @run do |f| %>
+ <div>
+ <%= f.label :game_id, "Game" %>
+ <%= f.collection_select :game_id, Game.all, :id, :title, {prompt: "Choose..."} %>
+ </div>
+
+ <div>
+ <%= f.label :title %>
+ <%= f.text_field :title %>
+ </div>
+
+ <div>
+ <%= f.label :description %>
+ <%= f.text_area :description %>
+ </div>
+
+ <div>
+ <%= f.submit "Start run" %>
+ </div>
+
+ <% if @run.errors.any? %>
+ <div>
+ <p><%= pluralize(@run.errors.count, "error") %> prohibited this run from being saved:</p>
+ <ul>
+ <% @run.errors.full_messages.each do |message| %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+<% end %>
diff --git a/app/views/runs/show.html.erb b/app/views/runs/show.html.erb
new file mode 100644
index 0000000..adb41e4
--- /dev/null
+++ b/app/views/runs/show.html.erb
@@ -0,0 +1,4 @@
+<h1 class="text-2xl"><%= @run.title %></h1>
+<p class="subtitle"><%= @run.game.title %></p>
+
+<p>Run started by: <%= @run.user.email %></p>