From 352beedd67024f2ca5257a5bbcf40144e0c6319f Mon Sep 17 00:00:00 2001 From: f Date: Fri, 15 Nov 2019 13:35:27 -0300 Subject: [PATCH] crear articulo segun layout --- app/controllers/posts_controller.rb | 2 +- app/services/post_service.rb | 4 ++-- app/views/posts/_form.haml | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 14af15fa..c9ea8d23 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -34,7 +34,7 @@ class PostsController < ApplicationController usuarie: current_usuarie, params: params) - if service.create.persisted? + if (@post = service.create.persisted?) redirect_to site_posts_path(@site) else render 'posts/new' diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 768c1fdd..0f6bac19 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -8,8 +8,8 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do # # @return Post def create - # TODO: Implementar layout - self.post = site.posts(lang: params[:post][:lang] || I18n.locale).build + self.post = site.posts(lang: params[:post][:lang] || I18n.locale) + .build(layout: params[:post][:layout]) post.usuaries << usuarie params[:post][:draft] = true if site.invitade? usuarie diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index 09136f3e..573389fb 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -19,6 +19,8 @@ -# Botones de guardado = render 'posts/submit', site: site, post: post + = hidden_field_tag 'post[layout]', params[:layout] || 'post' + -# Dibuja cada atributo - post.attributes.each do |attribute| - metadata = post.send(attribute)