From abade15c238e0b04af002e0de42a112dd14cde35 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 17 May 2018 15:14:51 -0300 Subject: [PATCH] no fallar si el sitio no tiene plantillas --- app/models/site.rb | 2 +- app/views/posts/index.haml | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index 7c423498..a3c3d8c4 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -111,7 +111,7 @@ class Site # Obtiene todas las plantillas de artículos def templates - @templates ||= posts_for('templates') + @templates ||= posts_for('templates') || [] end # Obtiene todos los posts de una colección determinada diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 5b88d24d..7869e38c 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -12,17 +12,18 @@ .btn-group = link_to t('posts.new'), new_site_post_path(@site, lang: @lang), class: 'btn btn-success' - %button.btn.btn-success.dropdown-toggle.dropdown-toggle-split{data: { toggle: 'split' }, - aria: { haspopup: 'true', expanded: 'false' }} - %span.sr-only= t('posts.dropdown') - .dropdown-menu - - @site.templates.each do |template| - = link_to template.id.camelize, - new_site_post_path(@site, lang: @lang, template: template.id), + - unless @site.templates.empty? + %button.btn.btn-success.dropdown-toggle.dropdown-toggle-split{data: { toggle: 'split' }, + aria: { haspopup: 'true', expanded: 'false' }} + %span.sr-only= t('posts.dropdown') + .dropdown-menu + - @site.templates.each do |template| + = link_to template.id.camelize, + new_site_post_path(@site, lang: @lang, template: template.id), + class: 'dropdown-item' + .dropdown-divider + = link_to t('templates.index'), site_templates_path(@site), class: 'dropdown-item' - .dropdown-divider - = link_to t('templates.index'), site_templates_path(@site), - class: 'dropdown-item' - @site.translations.each do |l| = link_to t("i18n.#{l}"), site_posts_path(@site, category: @category, lang: l), class: 'btn btn-info'