From c0c0e060ce83a1d9efc7cb340c9ebf1eeb8eded5 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 17 May 2018 16:06:08 -0300 Subject: [PATCH] no fallar si no usamos una plantilla --- app/controllers/application_controller.rb | 2 +- app/models/post.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3e3a9f24..fabd520f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -39,7 +39,7 @@ class ApplicationController < ActionController::Base end def find_template(site) - id = params[:template_id] || params[:template] || params.require(:post).require(:layout) + id = params[:template_id] || params[:template] || params.dig(:post, :layout) site.templates.find do |t| t.id == id end diff --git a/app/models/post.rb b/app/models/post.rb index 5c7149d2..7e98c99e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -63,6 +63,7 @@ class Post load_front_matter! merge_with_front_matter! front_matter.stringify_keys end + end # Limpiar los errores @@ -222,6 +223,7 @@ class Post end def template_fields + return [] unless template @template_fields ||= template.front_matter.reject do |key, _| REJECT_FROM_TEMPLATE.include? key end.keys @@ -312,7 +314,9 @@ class Post # Completa el front_matter a partir de las variables de otro def front_matter_from_template - return {} unless template + # XXX: Llamamos a @template en lugar de template porque sino + # entramos en una race condition + return {} unless @template # Convertimos el slug en layout ft = template.front_matter.dup