From 1f377437e46ab4dc20701515924be616eb097d42 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 17 May 2018 15:04:33 -0300 Subject: [PATCH] siempre encontrar la plantilla --- app/controllers/application_controller.rb | 2 +- app/controllers/posts_controller.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 28b009af..3e3a9f24 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] + id = params[:template_id] || params[:template] || params.require(:post).require(:layout) site.templates.find do |t| t.id == id end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 7fe23a87..5ffd710b 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -33,7 +33,9 @@ class PostsController < ApplicationController def create @site = find_site @lang = find_lang(@site) - @post = Post.new(site: @site, front_matter: post_params.to_hash, lang: @lang) + @template = find_template(@site) + @post = Post.new(site: @site, lang: @lang, template: @template) + @post.update_attributes(post_params) if @post.save redirect_to site_posts_path(@site, lang: @lang)