mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 04:21:41 +00:00
volver a los sitios si el sitio no se encuentra
This commit is contained in:
parent
1fd0649993
commit
c45446f40a
2 changed files with 24 additions and 3 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
# Forma de ingreso a Sutty
|
||||
class ApplicationController < ActionController::Base
|
||||
include ExceptionHandler
|
||||
|
||||
protect_from_forgery with: :exception
|
||||
before_action :set_locale
|
||||
|
||||
|
@ -17,10 +19,13 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
# Encontrar un sitio por su nombre
|
||||
def find_site
|
||||
current_usuarie.sites.find_by_name(params[:site_id] || params[:id])
|
||||
id = params[:site_id] || params[:id]
|
||||
|
||||
# TODO: reenviar a un 403 si el sitio ya no está permitido para le
|
||||
# usuarie
|
||||
unless (site = current_usuarie.sites.find_by_name(id))
|
||||
raise SiteNotFound
|
||||
end
|
||||
|
||||
site
|
||||
end
|
||||
|
||||
def find_post(site)
|
||||
|
|
16
app/controllers/concerns/exception_handler.rb
Normal file
16
app/controllers/concerns/exception_handler.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Gestiona las excepciones que lanzamos desde los controladores
|
||||
module ExceptionHandler
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class SiteNotFound < StandardError; end
|
||||
|
||||
included do
|
||||
rescue_from SiteNotFound, with: :site_not_found
|
||||
end
|
||||
|
||||
def site_not_found
|
||||
redirect_to sites_path
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue