class PostsController < ApplicationController before_action :authenticate! def index @site = find_site end def show @site = find_site @post = find_post(@site) end def edit @site = find_site @post = find_post(@site) end def update p = post_params @site = find_site @post = find_post(@site) # crear un array a partir de una cadena separada por comas [:tags,:categories].each do |comma| p[comma] = p.dig(comma).split(',').map(&:strip) end @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