From d7fa03a65eee7f9de8d3202cd7b865f5852d9d85 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 27 Feb 2018 20:32:10 -0300 Subject: [PATCH] usar los datos de la coleccion del post no del idioma por defecto --- app/models/site.rb | 13 +++++++------ app/views/posts/_form.haml | 16 ++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index 97f37b1d..104b9e84 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -101,16 +101,17 @@ class Site end end - def categories - everything_of :categories + def categories(lang: nil) + everything_of :categories, lang: lang end - def tags - everything_of :tags + def tags(lang: nil) + everything_of :tags, lang: lang end - def everything_of(attr) - posts.map do |p| + def everything_of(attr, lang: nil) + collection = lang || 'posts' + posts_for(collection).map do |p| p.get_front_matter attr end.flatten.uniq end diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index 734f3bfb..e5264a2b 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -42,12 +42,12 @@ = render 'layouts/help', help: t('help.autocomplete_html') = label_tag 'post_categories', t('posts.categories') = select_tag 'post[categories][]', - options_for_select(@site.categories, @post.categories), + options_for_select(@site.categories(lang: @lang), @post.categories), { class: 'form-control select2', multiple: 'multiple' } .form-group = label_tag 'post_tags', t('posts.tags') = select_tag 'post[tags][]', - options_for_select(@site.tags, @post.tags), + options_for_select(@site.tags(lang: @lang), @post.tags), { class: 'form-control select2', multiple: 'multiple' } .form-group = label_tag 'post_slug', t('posts.slug') @@ -67,7 +67,7 @@ .form-group = label_tag 'post_layout', t('posts.layout') = select_tag 'post[layout]', - options_for_select(@site.everything_of(:layout), @post.get_front_matter(:layout)), + options_for_select(@site.everything_of(:layout, lang: @lang), @post.get_front_matter(:layout)), { class: 'form-control select2' } %small.text-muted.form-text= t('posts.layout_help') .form-group @@ -88,31 +88,31 @@ .form-group = label_tag 'post_habilidades', t('posts.habilidades') = select_tag 'post[habilidades]', - options_for_select(@site.everything_of(:habilidades), @post.get_front_matter(:habilidades)), + options_for_select(@site.everything_of(:habilidades, lang: @lang), @post.get_front_matter(:habilidades)), { class: 'form-control select2' } %small.text-muted.form-text= t('posts.habilidades_help') .form-group = label_tag 'post_formato', t('posts.formato') = select_tag 'post[formato]', - options_for_select(@site.everything_of(:formato), @post.get_front_matter(:formato)), + options_for_select(@site.everything_of(:formato, lang: @lang), @post.get_front_matter(:formato)), { class: 'form-control select2' } %small.text-muted.form-text= t('posts.formato_help') .form-group = label_tag 'post_conocimientos', t('posts.conocimientos') = select_tag 'post[conocimientos][]', - options_for_select(@site.everything_of(:conocimientos), @post.get_front_matter(:conocimientos)), + options_for_select(@site.everything_of(:conocimientos, lang: @lang), @post.get_front_matter(:conocimientos)), { class: 'form-control select2', multiple: 'multiple' } %small.text-muted.form-text= t('posts.conocimientos_help') .form-group = label_tag 'post_sesiones_ejercicios_relacionados', t('posts.sesiones_ejercicios_relacionados') = select_tag 'post[sesiones_ejercicios_relacionados][]', - options_for_select(@site.everything_of(:title), @post.get_front_matter(:sesiones_ejercicios_relacionados)), + options_for_select(@site.everything_of(:title, lang: @lang), @post.get_front_matter(:sesiones_ejercicios_relacionados)), { class: 'form-control select2', multiple: 'multiple' } %small.text-muted.form-text= t('posts.sesiones_ejercicios_relacionados_help') .form-group = label_tag 'post_materiales_requeridos', t('posts.materiales_requeridos') = select_tag 'post[materiales_requeridos][]', - options_for_select(@site.everything_of(:materiales_requeridos), @post.get_front_matter(:materiales_requeridos)), + options_for_select(@site.everything_of(:materiales_requeridos, lang: @lang), @post.get_front_matter(:materiales_requeridos)), { class: 'form-control select2', multiple: 'multiple' } %small.text-muted.form-text= t('posts.materiales_requeridos_help') - I18n.available_locales.map(&:to_s).each do |lang|