From 8d622d625fc618051e277866df20826d9ab75de9 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 31 Oct 2019 17:34:23 -0300 Subject: [PATCH] empezar a implementar layouts --- app/controllers/posts_controller.rb | 3 +-- app/models/post_relation.rb | 2 +- app/models/site.rb | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 4ef6b3b..635cfe2 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -31,8 +31,7 @@ class PostsController < ApplicationController def new authorize Post @site = find_site - # TODO: Implementar layout - @post = @site.posts.build(lang: I18n.locale) + @post = @site.posts.build(lang: I18n.locale, layout: params[:layout]) end def create diff --git a/app/models/post_relation.rb b/app/models/post_relation.rb index 9e0df2e..40ccaa9 100644 --- a/app/models/post_relation.rb +++ b/app/models/post_relation.rb @@ -57,7 +57,7 @@ class PostRelation < Array def build_layout(layout = nil) return layout if layout.is_a? Layout - site.layouts[layout || :post] + site.layouts[layout.try(:to_sym) || :post] end # Devuelve una colección Jekyll que hace pasar el documento diff --git a/app/models/site.rb b/app/models/site.rb index 48ebb6e..72d9cce 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -206,8 +206,7 @@ class Site < ApplicationRecord # @return Array def everything_of(attr, lang: nil) posts(lang: lang).map do |p| - # XXX: Tener cuidado con los métodos que no existan - p.send(attr).try :value + p.send(attr).try(:value) if p.attribute? attr end.flatten.uniq.compact end