class PostsController < ApplicationController before_action :authenticate! def index @lang = find_lang @site = find_site @category = session[:category] = params.dig(:category) @posts = @site.posts_for(@lang) end def show @lang = find_lang @site = find_site @post = find_post(@site) end def new @lang = find_lang @site = find_site @post = Post.new(site: @site, front_matter: { date: Time.now }) end def create @lang = find_lang @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 @lang = find_lang @site = find_site @post = find_post(@site) end def update p = post_params @lang = find_lang @site = find_site @post = find_post(@site) @post.update_attributes(p) if @post.save redirect_to site_posts_path(@site, category: session[:category]) else render 'posts/edit' end end private # Solo permitir cambiar estos atributos de cada articulo def post_params params.require(:post).permit(:title, :date, :content, :slug, :cover, :layout, :permalink, :objetivos, :dir, :duracion, :formato, :habilidades, :recomendaciones, conocimientos: [], sesiones_ejercicios_relacionados: [], materiales_requeridos: [], lang: {}, tags: [], categories: []) end end