class PostsController < ApplicationController before_action :authenticate! def index @site = find_site end def show @site = find_site @post = find_post(@site) end def new @site = find_site @post = Post.new(site: @site, front_matter: { date: Time.now }) end def create @site = find_site @post = Post.new(site: @site, front_matter: post_params.to_hash) if @post.save redirect_to site_posts_path(@site) else render 'posts/new' end end def edit @site = find_site @post = find_post(@site) end def update p = post_params @site = find_site @post = find_post(@site) @post.update_attributes(p) if @post.save redirect_to site_post_path(@site, @post) else render 'posts/edit' end end private # Solo permitir cambiar estos atributos de cada articulo def post_params params.require(:post).permit(:title, :date, :tags, :categories, :content, :slug) end end