diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 28b009a..3e3a9f2 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 7fe23a8..5ffd710 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)