mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-14 23:01:41 +00:00
errores 404 cuando no se encuentran los recursos
This commit is contained in:
parent
17e5705dff
commit
50f83c9e7e
10 changed files with 72 additions and 62 deletions
|
@ -8,6 +8,7 @@ $magenta: #f206f9;
|
|||
|
||||
// Redefinir variables de Bootstrap
|
||||
$primary: $magenta;
|
||||
$jumbotron-bg: transparent;
|
||||
|
||||
@import "bootstrap";
|
||||
|
||||
|
@ -294,3 +295,7 @@ svg {
|
|||
height: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.vh-100 {
|
||||
height: 100vh !important;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,7 @@ class ApplicationController < ActionController::Base
|
|||
around_action :set_locale
|
||||
|
||||
before_action do
|
||||
if current_usuarie.try(:ends_with?, '@' + ENV.fetch('SUTTY', 'sutty.nl'))
|
||||
Rack::MiniProfiler.authorize_request
|
||||
end
|
||||
Rack::MiniProfiler.authorize_request if current_usuarie.try(:ends_with?, '@' + ENV.fetch('SUTTY', 'sutty.nl'))
|
||||
end
|
||||
|
||||
# No tenemos índice de sutty, vamos directamente a ver el listado de
|
||||
|
@ -42,6 +40,11 @@ class ApplicationController < ActionController::Base
|
|||
I18n.with_locale(current_usuarie.try(:lang) || I18n.default_locale, &action)
|
||||
end
|
||||
|
||||
# Muestra una página 404
|
||||
def page_not_found
|
||||
render 'application/page_not_found', status: :not_found
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def configure_permitted_parameters
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
# Controlador para artículos
|
||||
class PostsController < ApplicationController
|
||||
include Pundit
|
||||
rescue_from Pundit::NilPolicyError, with: :page_not_found
|
||||
|
||||
before_action :authenticate_usuarie!
|
||||
|
||||
# Las URLs siempre llevan el idioma actual o el de le usuarie
|
||||
|
@ -32,6 +34,7 @@ class PostsController < ApplicationController
|
|||
def show
|
||||
@site = find_site
|
||||
@post = @site.posts(lang: locale).find params[:id]
|
||||
|
||||
authorize @post
|
||||
@locale = locale
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
# Controlador de sitios
|
||||
class SitesController < ApplicationController
|
||||
include Pundit
|
||||
rescue_from Pundit::NilPolicyError, with: :page_not_found
|
||||
|
||||
before_action :authenticate_usuarie!
|
||||
|
||||
# Ver un listado de sitios
|
||||
|
|
15
app/policies/nil_class_policy.rb
Normal file
15
app/policies/nil_class_policy.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Una política para mostrar un error 404 cuando no se puede encontrar el
|
||||
# recurso.
|
||||
#
|
||||
# @see app/controllers/application_controller.rb
|
||||
# @see app/controllers/posts_controller.rb
|
||||
# @see app/controllers/site_controller.rb
|
||||
class Pundit::NilPolicyError < RuntimeError; end
|
||||
|
||||
class NilClassPolicy
|
||||
def initialize(_, _)
|
||||
raise Pundit::NilPolicyError
|
||||
end
|
||||
end
|
6
app/views/application/page_not_found.haml
Normal file
6
app/views/application/page_not_found.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
%main.vh-100.p-0.d-flex.align-items-center
|
||||
%div
|
||||
%h1= t('.title')
|
||||
|
||||
%p= t('.description')
|
||||
%p= link_to t('.button'), '/'
|
|
@ -457,3 +457,8 @@ en:
|
|||
invitaciones: 'You can invite new %{invite_as} by entering an email address per line. They will receive an email with your invitation and decide if they want to accept or not.'
|
||||
invitaciones: Send invitations to these addresses
|
||||
submit: Send invitations
|
||||
application:
|
||||
page_not_found:
|
||||
title: '404: Page not found :('
|
||||
description: "You're reading this message because the page you wanted doesn't exist."
|
||||
button: 'Back to panel'
|
||||
|
|
|
@ -465,3 +465,8 @@ es:
|
|||
invitaciones: 'Invita nueves %{invite_as} ingresando una dirección de correo electrónico por línea. Recibirán un correo con tu invitación y podrán aceptarla o no.'
|
||||
invitaciones: Invitar a estas direcciones
|
||||
submit: Enviar invitaciones
|
||||
application:
|
||||
page_not_found:
|
||||
title: '404: Página no encontrada :('
|
||||
description: 'Estás leyendo este error porque la página que quisiste acceder no existe.'
|
||||
button: 'Volver al panel'
|
||||
|
|
|
@ -1,67 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>The page you were looking for doesn't exist (404)</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<style>
|
||||
.rails-default-error-page {
|
||||
background-color: #EFEFEF;
|
||||
color: #2E2F30;
|
||||
text-align: center;
|
||||
font-family: arial, sans-serif;
|
||||
margin: 0;
|
||||
}
|
||||
<head>
|
||||
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
|
||||
<title>Sutty</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
|
||||
<script defer type="text/javascript" src="https://sutty.nl/assets/js/client_side_i18n.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class='container-fluid'>
|
||||
<div class='row'>
|
||||
<main class="jumbotron">
|
||||
<section id="castellano" lang="es">
|
||||
<h1>404: Dirección web no encontrada</h1>
|
||||
|
||||
.rails-default-error-page div.dialog {
|
||||
width: 95%;
|
||||
max-width: 33em;
|
||||
margin: 4em auto 0;
|
||||
}
|
||||
<p>Estás leyendo este mensaje porque la dirección web a la que quisiste acceder no existe :(</p>
|
||||
|
||||
.rails-default-error-page div.dialog > div {
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-left-color: #999;
|
||||
border-bottom-color: #BBB;
|
||||
border-top: #B00100 solid 4px;
|
||||
border-top-left-radius: 9px;
|
||||
border-top-right-radius: 9px;
|
||||
background-color: white;
|
||||
padding: 7px 12% 0;
|
||||
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
||||
}
|
||||
<p><a href="/">Volver al panel</a></p>
|
||||
</section>
|
||||
|
||||
.rails-default-error-page h1 {
|
||||
font-size: 100%;
|
||||
color: #730E15;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
<section id="english" lang="en">
|
||||
<h1>404: Address not found</h1>
|
||||
|
||||
.rails-default-error-page div.dialog > p {
|
||||
margin: 0 0 1em;
|
||||
padding: 1em;
|
||||
background-color: #F7F7F7;
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-left-color: #999;
|
||||
border-bottom-color: #999;
|
||||
border-bottom-left-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
border-top-color: #DADADA;
|
||||
color: #666;
|
||||
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<p>You're reading this message because the address you wanted doesn't exist :(</p>
|
||||
|
||||
<body class="rails-default-error-page">
|
||||
<!-- This file lives in public/404.html -->
|
||||
<div class="dialog">
|
||||
<div>
|
||||
<h1>The page you were looking for doesn't exist.</h1>
|
||||
<p>You may have mistyped the address or the page may have moved.</p>
|
||||
<p><a href="/">Go to panel</a></p>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<p>If you are the application owner check the logs for more information.</p>
|
||||
</div>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
<head>
|
||||
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
|
||||
<title>Sutty</title>
|
||||
<link rel="stylesheet" media="all" href="https://getbootstrap.com/docs/4.1/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
|
||||
<script defer type="text/javascript" src="https://sutty.nl/assets/js/client_side_i18n.js"></script>
|
||||
</head>
|
||||
<body class=''>
|
||||
<div class='container-fluid'>
|
||||
|
|
Loading…
Reference in a new issue