diff options
-rw-r--r-- | app/controllers/application_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/home_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/runs_controller.rb | 29 | ||||
-rw-r--r-- | app/helpers/run_helper.rb | 2 | ||||
-rw-r--r-- | app/models/checkpoint.rb | 2 | ||||
-rw-r--r-- | app/models/game.rb | 2 | ||||
-rw-r--r-- | app/models/run.rb | 2 | ||||
-rw-r--r-- | app/views/layouts/application.html.erb | 2 | ||||
-rw-r--r-- | app/views/runs/new.html.erb | 31 | ||||
-rw-r--r-- | app/views/runs/show.html.erb | 4 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | db/seeds.rb | 14 | ||||
-rw-r--r-- | test/controllers/runs_controller_test.rb | 4 |
13 files changed, 94 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> diff --git a/config/routes.rb b/config/routes.rb index c6cd35b..a267aa8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,4 +8,6 @@ Rails.application.routes.draw do # Defines the root path route ("/") root "home#index" + + resources :runs end diff --git a/db/seeds.rb b/db/seeds.rb index 4fbd6ed..ce6f747 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,3 +7,17 @@ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| # MovieGenre.find_or_create_by!(name: genre_name) # end + +[ + "Pokémon Red", "Pokémon Blue", "Pokémon Yellow", "Pokémon Gold", "Pokémon Silver", + "Pokémon Crystal", "Pokémon Ruby", "Pokémon Sapphire", "Pokémon Emerald", + "Pokémon FireRed", "Pokémon LeafGreen", "Pokémon Diamond", "Pokémon Pearl", + "Pokémon Platinum", "Pokémon HeartGold", "Pokémon SoulSilver", "Pokémon Black", + "Pokémon White", "Pokémon Black 2", "Pokémon White 2", "Pokémon X", "Pokémon Y", + "Pokémon Omega Ruby", "Pokémon Alpha Sapphire", "Pokémon Sun", "Pokémon Moon", + "Pokémon Ultra Sun", "Pokémon Ultra Moon", "Pokémon Let's Go, Pikachu!", + "Pokémon Let's Go, Eevee!", "Pokémon Sword", "Pokémon Shield", + "Pokémon Brilliant Diamond", "Pokémon Shining Pearl", "Pokémon Legends: Arceus" +].each do |title| + Game.create(title:) +end diff --git a/test/controllers/runs_controller_test.rb b/test/controllers/runs_controller_test.rb new file mode 100644 index 0000000..fc14be9 --- /dev/null +++ b/test/controllers/runs_controller_test.rb @@ -0,0 +1,4 @@ +require "test_helper" + +class RunsControllerTest < ActionDispatch::IntegrationTest +end |