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

permitir cambiar de idioma

This commit is contained in:
f 2020-03-19 15:31:29 -03:00
parent 8fcbc2280f
commit 26247a9544
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
2 changed files with 27 additions and 7 deletions

View file

@ -11,21 +11,21 @@ class PostsController < ApplicationController
@category = session[:category] = params.dig(:category) @category = session[:category] = params.dig(:category)
@layout = params.dig(:layout).try :to_sym @layout = params.dig(:layout).try :to_sym
# TODO: Aplicar policy_scope # TODO: Aplicar policy_scope
@posts = @site.posts(lang: I18n.locale) @posts = @site.posts(lang: lang)
@posts.sort_by!(:order, :date).reverse! @posts.sort_by!(:order, :date).reverse!
@usuarie = @site.usuarie? current_usuarie @usuarie = @site.usuarie? current_usuarie
end end
def show def show
@site = find_site @site = find_site
@post = @site.posts.find params[:id] @post = @site.posts(lang: lang).find params[:id]
authorize @post authorize @post
end end
def new def new
authorize Post authorize Post
@site = find_site @site = find_site
@post = @site.posts.build(lang: I18n.locale, layout: params[:layout]) @post = @site.posts.build(lang: lang, layout: params[:layout])
end end
def create def create
@ -44,14 +44,14 @@ class PostsController < ApplicationController
def edit def edit
@site = find_site @site = find_site
@post = @site.posts.find params[:id] @post = @site.posts(lang: lang).find params[:id]
authorize @post authorize @post
end end
def update def update
@site = find_site @site = find_site
@post = @site.posts.find params[:id] @post = @site.posts(lang: lang).find params[:id]
authorize @post authorize @post
@ -70,7 +70,7 @@ class PostsController < ApplicationController
# Eliminar artículos # Eliminar artículos
def destroy def destroy
@site = find_site @site = find_site
@post = @site.posts.find params[:id] @post = @site.posts(lang: lang).find params[:id]
authorize @post authorize @post
@ -96,4 +96,13 @@ class PostsController < ApplicationController
service.reorder service.reorder
redirect_to site_posts_path(@site) redirect_to site_posts_path(@site)
end end
# Devuelve el idioma solicitado a través de un parámetro, validando
# que el sitio soporte ese idioma
def lang
return unless params[:lang]
return unless @site.try(:locales).try(:include?, params[:lang])
params[:lang]
end
end end

View file

@ -102,8 +102,19 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
end end
end end
# Devuelve el idioma solicitado a través de un parámetro, validando
# que el sitio soporte ese idioma
#
# TODO: DRY
def lang def lang
params[:post][:lang] || I18n.locale return unless params[:lang]
return unless site.try(:locales).try(:include?, params[:lang])
params[:lang]
end
def layout
params.dig(:post, :layout) || params[:layout]
end end
end end
# rubocop:enable Metrics/BlockLength # rubocop:enable Metrics/BlockLength