summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/users_controller.rb31
-rw-r--r--app/helpers/users_helper.rb2
-rw-r--r--app/models/user.rb3
-rw-r--r--app/views/layouts/application.html.erb2
-rw-r--r--app/views/users/show.html.erb19
-rw-r--r--config/routes.rb1
-rw-r--r--test/controllers/users_controller_test.rb7
7 files changed, 64 insertions, 1 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
new file mode 100644
index 0000000..f411ace
--- /dev/null
+++ b/app/controllers/users_controller.rb
@@ -0,0 +1,31 @@
+class UsersController < ApplicationController
+ before_action :set_user
+ before_action :validate_current_user, except: [:show]
+
+ def show; end
+
+ def edit; end
+
+ def update
+ @user.set(user_params)
+ if @user.save
+ redirect_to run_path(@run), notice: "Saved profile."
+ else
+ render :edit, status: :unprocessable_entity
+ end
+ end
+
+protected
+
+ def set_user
+ @user = User.find(params[:id])
+ end
+
+ def validate_current_user
+ redirect_to user_path(current_user) unless @user == current_user
+ end
+
+ def user_params
+ params.require(:user).permit(:name)
+ end
+end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
new file mode 100644
index 0000000..2310a24
--- /dev/null
+++ b/app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 4609a80..27ff9b2 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -2,4 +2,7 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :rememberable
+
+ has_many :runs, dependent: :restrict_with_error
+ has_many :checkpoints, through: :runs
end
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 3dad62b..a7ac625 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -23,7 +23,7 @@
</div>
<div class="space-x-8 nav-links">
<% if user_signed_in? %>
- <%= link_to "Profile", "#" %>
+ <%= link_to "Profile", user_path(current_user) %>
<%= link_to "Sign out", destroy_user_session_path %>
<% else %>
<%= link_to "Sign in", new_user_session_path %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
new file mode 100644
index 0000000..ad6675a
--- /dev/null
+++ b/app/views/users/show.html.erb
@@ -0,0 +1,19 @@
+<div class="space-y-4">
+ <h1 class="text-2xl">
+ <span class="px-4 py-2 text-lg text-slate-900 bg-orange-600 rounded">TRAINER CARD</span>
+ <%= @user.name || "Unknown" %>
+ </h1>
+ <p class="subtitle">ID No. <%= @user.id %></p>
+
+ <ul>
+ <li>Pokédex 0</li>
+ </ul>
+
+ <h2><%= pluralize(@user.runs.count, "run") %></h2>
+
+ <ul class="list-disc">
+ <% @user.runs.each do |run| %>
+ <li><%= run.game.title %> - <%= link_to run.title, run_path(run) %></li>
+ <% end %>
+ </ul>
+</div>
diff --git a/config/routes.rb b/config/routes.rb
index c601180..c578005 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -12,4 +12,5 @@ Rails.application.routes.draw do
resources :runs do
resources :checkpoints
end
+ resources :users, except: [:destroy]
end
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb
new file mode 100644
index 0000000..61c1532
--- /dev/null
+++ b/test/controllers/users_controller_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class UsersControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end