siempre encontrar la plantilla

This commit is contained in:
f 2018-05-17 15:04:33 -03:00
parent 33713af201
commit 1f377437e4
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
2 changed files with 4 additions and 2 deletions

View file

@ -39,7 +39,7 @@ class ApplicationController < ActionController::Base
end end
def find_template(site) 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| site.templates.find do |t|
t.id == id t.id == id
end end

View file

@ -33,7 +33,9 @@ class PostsController < ApplicationController
def create def create
@site = find_site @site = find_site
@lang = find_lang(@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 if @post.save
redirect_to site_posts_path(@site, lang: @lang) redirect_to site_posts_path(@site, lang: @lang)