5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2025-03-16 18:18:19 +00:00
panel/app/controllers/application_controller.rb

44 lines
832 B
Ruby

# Forma de ingreso a Sutty
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :set_locale
# No tenemos índice de sutty, vamos directamente a ver el listado de
# sitios
def index
redirect_to sites_path
end
def markdown
end
private
# Encontrar un sitio por su ID
# TODO volverlo más natural a rails
def find_site
id = params[:site_id] || params[:id]
current_user.sites.find do |s|
s.id == id
end
end
def find_post(site)
id = params[:post_id] || params[:id]
lang = find_lang
posts = site.posts_for(lang)
posts.find do |p|
p.id == id
end
end
def find_lang
params.fetch(:lang, I18n.locale.to_s)
end
def set_locale
I18n.locale = session[:lang] if session[:lang].present?
end
end