mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 07:11:43 +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
|
# Forma de ingreso a Sutty
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
include ExceptionHandler
|
||||||
|
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
before_action :set_locale
|
before_action :set_locale
|
||||||
|
|
||||||
|
@ -17,10 +19,13 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
# Encontrar un sitio por su nombre
|
# Encontrar un sitio por su nombre
|
||||||
def find_site
|
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
|
unless (site = current_usuarie.sites.find_by_name(id))
|
||||||
# usuarie
|
raise SiteNotFound
|
||||||
|
end
|
||||||
|
|
||||||
|
site
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_post(site)
|
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