Organise with layouts
This commit is contained in:
parent
54b25a061e
commit
caa45332b0
@ -2,4 +2,16 @@ class ApplicationController < ActionController::Base
|
|||||||
include Authentication
|
include Authentication
|
||||||
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
||||||
allow_browser versions: :modern
|
allow_browser versions: :modern
|
||||||
|
before_action :set_title, :set_current_user
|
||||||
|
layout "authenticated"
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_title
|
||||||
|
@title = "Public scoreboard"
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_current_user
|
||||||
|
@current_user = current_user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,14 +3,16 @@ class ContestsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@contests = current_user.contests
|
@contests = current_user.contests
|
||||||
@user = current_user
|
@title = "Welcome #{current_user.username}!"
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@title = "Contest: #{@contest.name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@contest = Contest.new
|
@contest = Contest.new
|
||||||
|
@title = "Create a new jigsaw puzzle competition"
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -2,9 +2,11 @@ class UsersController < ApplicationController
|
|||||||
before_action :set_user, only: %i[ destroy edit update show ]
|
before_action :set_user, only: %i[ destroy edit update show ]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@title = "All users"
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@title = "My settings"
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@ -16,6 +18,7 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
redirect_to edit_user_path(@user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
8
app/views/contests/_form.html.slim
Normal file
8
app/views/contests/_form.html.slim
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
= form_with model: contest do |form|
|
||||||
|
.row
|
||||||
|
.col.g-3
|
||||||
|
.form-floating.mt-5
|
||||||
|
= form.text_field :name, autocomplete: "off", class: "form-control"
|
||||||
|
= form.label :name, class: "required"
|
||||||
|
div.mt-3
|
||||||
|
= form.submit
|
@ -1,14 +1,3 @@
|
|||||||
- if authenticated?
|
|
||||||
.float-end.ms-3
|
|
||||||
= button_to "Log out", session_path, method: :delete
|
|
||||||
.float-end.mt-1
|
|
||||||
= link_to "Settings", user_path(@user)
|
|
||||||
|
|
||||||
h1 Welcome!
|
|
||||||
|
|
||||||
.alert.alert-primary role="alert"
|
|
||||||
| This is a brand new website!
|
|
||||||
|
|
||||||
h4.mt-4 Manage your contests
|
h4.mt-4 Manage your contests
|
||||||
|
|
||||||
- @contests.each do |contest|
|
- @contests.each do |contest|
|
||||||
|
@ -1,8 +1 @@
|
|||||||
h1 Create a new contest
|
= render "form", contest: @contest
|
||||||
|
|
||||||
= form_with model: @contest do |form|
|
|
||||||
div
|
|
||||||
= form.label :name
|
|
||||||
= form.text_field :name
|
|
||||||
div
|
|
||||||
= form.submit
|
|
@ -1,4 +0,0 @@
|
|||||||
h1 Contest: "#{@contest.name}"
|
|
||||||
|
|
||||||
a.btn.btn-primary href=root_path
|
|
||||||
| Back to all contests
|
|
16
app/views/layouts/_header.html.slim
Normal file
16
app/views/layouts/_header.html.slim
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
head
|
||||||
|
title Puzzle Scoreboard
|
||||||
|
meta name="viewport" content="width=device-width,initial-scale=1"
|
||||||
|
meta name="apple-mobile-web-app-capable" content="yes"
|
||||||
|
meta name="mobile-web-app-capable" content="yes"
|
||||||
|
= csrf_meta_tags
|
||||||
|
= csp_meta_tag
|
||||||
|
|
||||||
|
= yield :head
|
||||||
|
|
||||||
|
link rel="icon" href="/icon.png" type="image/png"
|
||||||
|
link rel="icon" href="/icon.svg" type="image/svg+xml"
|
||||||
|
link rel="apple-touch-icon" href="/icon.png"
|
||||||
|
|
||||||
|
= stylesheet_link_tag :app, "data-turbo-track": "reload"
|
||||||
|
= javascript_importmap_tags
|
@ -1,21 +1,6 @@
|
|||||||
doctype html
|
doctype html
|
||||||
html
|
html
|
||||||
head
|
= render "layouts/header"
|
||||||
title Puzzle Scoreboard
|
|
||||||
meta name="viewport" content="width=device-width,initial-scale=1"
|
|
||||||
meta name="apple-mobile-web-app-capable" content="yes"
|
|
||||||
meta name="mobile-web-app-capable" content="yes"
|
|
||||||
= csrf_meta_tags
|
|
||||||
= csp_meta_tag
|
|
||||||
|
|
||||||
= yield :head
|
|
||||||
|
|
||||||
link rel="icon" href="/icon.png" type="image/png"
|
|
||||||
link rel="icon" href="/icon.svg" type="image/svg+xml"
|
|
||||||
link rel="apple-touch-icon" href="/icon.png"
|
|
||||||
|
|
||||||
= stylesheet_link_tag :app, "data-turbo-track": "reload"
|
|
||||||
= javascript_importmap_tags
|
|
||||||
|
|
||||||
body
|
body
|
||||||
.container.mt-5
|
.container.mt-5
|
||||||
|
16
app/views/layouts/authenticated.html.slim
Normal file
16
app/views/layouts/authenticated.html.slim
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
doctype html
|
||||||
|
html
|
||||||
|
= render "layouts/header"
|
||||||
|
|
||||||
|
body
|
||||||
|
.container.mt-5
|
||||||
|
.float-end.ms-3
|
||||||
|
= button_to "Log out", session_path, method: :delete
|
||||||
|
.float-end.mt-1.ms-3
|
||||||
|
= link_to "Settings", user_path(@current_user)
|
||||||
|
.float-end.mt-1
|
||||||
|
= link_to "Home", contests_path
|
||||||
|
|
||||||
|
h1 = @title
|
||||||
|
|
||||||
|
= yield
|
@ -1,3 +1 @@
|
|||||||
h1 Edit settings
|
|
||||||
|
|
||||||
= render "form", user: @user
|
= render "form", user: @user
|
@ -1,3 +1 @@
|
|||||||
h1 Create a new user
|
|
||||||
|
|
||||||
= render "form", user: @user
|
= render "form", user: @user
|
@ -1,5 +1,3 @@
|
|||||||
h1 = @user.username
|
|
||||||
|
|
||||||
p
|
p
|
||||||
|> Email:
|
|> Email:
|
||||||
= @user.email_address
|
= @user.email_address
|
||||||
|
Loading…
x
Reference in New Issue
Block a user