5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 18:26:21 +00:00

errores 404 cuando no se encuentran los recursos

This commit is contained in:
f 2020-06-08 20:25:05 -03:00
parent 17e5705dff
commit 50f83c9e7e
10 changed files with 72 additions and 62 deletions

View file

@ -8,6 +8,7 @@ $magenta: #f206f9;
// Redefinir variables de Bootstrap // Redefinir variables de Bootstrap
$primary: $magenta; $primary: $magenta;
$jumbotron-bg: transparent;
@import "bootstrap"; @import "bootstrap";
@ -294,3 +295,7 @@ svg {
height: auto; height: auto;
} }
} }
.vh-100 {
height: 100vh !important;
}

View file

@ -9,9 +9,7 @@ class ApplicationController < ActionController::Base
around_action :set_locale around_action :set_locale
before_action do before_action do
if current_usuarie.try(:ends_with?, '@' + ENV.fetch('SUTTY', 'sutty.nl')) Rack::MiniProfiler.authorize_request if current_usuarie.try(:ends_with?, '@' + ENV.fetch('SUTTY', 'sutty.nl'))
Rack::MiniProfiler.authorize_request
end
end end
# No tenemos índice de sutty, vamos directamente a ver el listado de # 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) I18n.with_locale(current_usuarie.try(:lang) || I18n.default_locale, &action)
end end
# Muestra una página 404
def page_not_found
render 'application/page_not_found', status: :not_found
end
protected protected
def configure_permitted_parameters def configure_permitted_parameters

View file

@ -3,6 +3,8 @@
# Controlador para artículos # Controlador para artículos
class PostsController < ApplicationController class PostsController < ApplicationController
include Pundit include Pundit
rescue_from Pundit::NilPolicyError, with: :page_not_found
before_action :authenticate_usuarie! before_action :authenticate_usuarie!
# Las URLs siempre llevan el idioma actual o el de le usuarie # Las URLs siempre llevan el idioma actual o el de le usuarie
@ -32,6 +34,7 @@ class PostsController < ApplicationController
def show def show
@site = find_site @site = find_site
@post = @site.posts(lang: locale).find params[:id] @post = @site.posts(lang: locale).find params[:id]
authorize @post authorize @post
@locale = locale @locale = locale

View file

@ -3,6 +3,8 @@
# Controlador de sitios # Controlador de sitios
class SitesController < ApplicationController class SitesController < ApplicationController
include Pundit include Pundit
rescue_from Pundit::NilPolicyError, with: :page_not_found
before_action :authenticate_usuarie! before_action :authenticate_usuarie!
# Ver un listado de sitios # Ver un listado de sitios

View 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

View 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'), '/'

View file

@ -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: '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 invitaciones: Send invitations to these addresses
submit: Send invitations 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'

View file

@ -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: '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 invitaciones: Invitar a estas direcciones
submit: Enviar invitaciones 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'

View file

@ -1,67 +1,32 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>The page you were looking for doesn't exist (404)</title> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
<meta name="viewport" content="width=device-width,initial-scale=1"> <title>Sutty</title>
<style> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
.rails-default-error-page { <script defer type="text/javascript" src="https://sutty.nl/assets/js/client_side_i18n.js"></script>
background-color: #EFEFEF; </head>
color: #2E2F30; <body>
text-align: center; <div class='container-fluid'>
font-family: arial, sans-serif; <div class='row'>
margin: 0; <main class="jumbotron">
} <section id="castellano" lang="es">
<h1>404: Dirección web no encontrada</h1>
.rails-default-error-page div.dialog { <p>Estás leyendo este mensaje porque la dirección web a la que quisiste acceder no existe :(</p>
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
.rails-default-error-page div.dialog > div { <p><a href="/">Volver al panel</a></p>
border: 1px solid #CCC; </section>
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);
}
.rails-default-error-page h1 { <section id="english" lang="en">
font-size: 100%; <h1>404: Address not found</h1>
color: #730E15;
line-height: 1.5em;
}
.rails-default-error-page div.dialog > p { <p>You're reading this message because the address you wanted doesn't exist :(</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>
<body class="rails-default-error-page"> <p><a href="/">Go to panel</a></p>
<!-- This file lives in public/404.html --> </section>
<div class="dialog"> </main>
<div> </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>
</div> </div>
<p>If you are the application owner check the logs for more information.</p> </body>
</div>
</body>
</html> </html>

View file

@ -3,7 +3,8 @@
<head> <head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
<title>Sutty</title> <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> </head>
<body class=''> <body class=''>
<div class='container-fluid'> <div class='container-fluid'>