diff options
author | David Gay <eapoems@riseup.net> | 2023-10-30 02:26:25 -0400 |
---|---|---|
committer | David Gay <eapoems@riseup.net> | 2023-10-30 02:26:25 -0400 |
commit | 4c4b9b78e2a88b20680f3bf7b4cfcbc3da8de533 (patch) | |
tree | e385302e16d5da1b54c162860af4f3a7346c7d1e /app | |
parent | 13df3e5aadae04b322bff4cb0279b299e2c92a41 (diff) |
Checkpoint creation
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/checkpoints_controller.rb | 27 | ||||
-rw-r--r-- | app/helpers/checkpoints_helper.rb | 2 | ||||
-rw-r--r-- | app/views/checkpoints/new.html.erb | 31 | ||||
-rw-r--r-- | app/views/runs/show.html.erb | 11 |
4 files changed, 71 insertions, 0 deletions
diff --git a/app/controllers/checkpoints_controller.rb b/app/controllers/checkpoints_controller.rb new file mode 100644 index 0000000..94df2c3 --- /dev/null +++ b/app/controllers/checkpoints_controller.rb @@ -0,0 +1,27 @@ +class CheckpointsController < ApplicationController + before_action :set_run + + def new + @checkpoint = @run.checkpoints.build + end + + def create + @checkpoint = @run.checkpoints.build(checkpoint_params) + @checkpoint.user = current_user + if @checkpoint.save + redirect_to run_path(@run), notice: "Saved checkpoint." + else + render :new, status: :unprocessable_entity + end + end + +protected + + def checkpoint_params + params.require(:checkpoint).permit(:title, :description, :save_file) + end + + def set_run + @run = Run.find(params[:run_id]) + end +end diff --git a/app/helpers/checkpoints_helper.rb b/app/helpers/checkpoints_helper.rb new file mode 100644 index 0000000..421e4aa --- /dev/null +++ b/app/helpers/checkpoints_helper.rb @@ -0,0 +1,2 @@ +module CheckpointsHelper +end diff --git a/app/views/checkpoints/new.html.erb b/app/views/checkpoints/new.html.erb new file mode 100644 index 0000000..fc61e9f --- /dev/null +++ b/app/views/checkpoints/new.html.erb @@ -0,0 +1,31 @@ +<%= form_with model: [@run, @checkpoint] do |f| %> + <div> + <%= f.label :title %> + <%= f.text_field :title %> + </div> + + <div> + <%= f.label :description %> + <%= f.text_area :description %> + </div> + + <div> + <%= f.label :save_file %> + <%= f.file_field :save_file %> + </div> + + <div> + <%= f.submit "Submit checkpoint" %> + </div> + + <% if @checkpoint.errors.any? %> + <div> + <p><%= pluralize(@checkpoint.errors.count, "error") %> prohibited this checkpoint from being saved:</p> + <ul> + <% @checkpoint.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 index adb41e4..11fdd12 100644 --- a/app/views/runs/show.html.erb +++ b/app/views/runs/show.html.erb @@ -2,3 +2,14 @@ <p class="subtitle"><%= @run.game.title %></p> <p>Run started by: <%= @run.user.email %></p> + +<%= link_to "New checkpoint", new_run_checkpoint_path(@run) %> + +<h2 class="text-xl">Checkpoints</h2> + +<ul class="list-disc"> + <% @run.checkpoints.each do |checkpoint| %> + <li><%= checkpoint.created_at %> + <%= link_to "[save file]", rails_blob_path(checkpoint.save_file, disposition: "attachment") %></li> + <% end %> +</ul> |