procesar los campos de la plantilla como strong params

This commit is contained in:
f 2018-05-14 18:45:52 -03:00
parent 0d5c974f6d
commit f51aed84d6
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
2 changed files with 18 additions and 8 deletions

View file

@ -49,12 +49,11 @@ class PostsController < ApplicationController
end end
def update def update
p = post_params
@site = find_site @site = find_site
@lang = find_lang(@site) @lang = find_lang(@site)
@post = find_post(@site) @post = find_post(@site)
@post.update_attributes(p) @post.update_attributes(post_params)
if @post.save if @post.save
redirect_to site_posts_path(@site, category: session[:category], lang: @lang) redirect_to site_posts_path(@site, category: session[:category], lang: @lang)
@ -67,11 +66,10 @@ class PostsController < ApplicationController
# Solo permitir cambiar estos atributos de cada articulo # Solo permitir cambiar estos atributos de cada articulo
def post_params def post_params
params.require(:post).permit(:title, :date, :content, :slug, default_post_params = [:title, :date, :content, :slug, :cover,
:cover, :layout, :permalink, :objetivos, :dir, :layout, :permalink, :dir,
:duracion, :formato, :habilidades, :recomendaciones, { lang: {} }, { tags: [] }, { categories: [] }]
conocimientos: [], sesiones_ejercicios_relacionados: [],
materiales_requeridos: [], lang: {}, params.require(:post).permit(default_post_params + @post.template_params)
tags: [], categories: [])
end end
end end

View file

@ -227,6 +227,18 @@ class Post
end.keys end.keys
end end
# devuelve las plantillas como strong params
def template_params
@template_params ||= template_fields.map do |k|
v = template.get_front_matter(k)
if v.is_a? Array
{ k.to_sym => [] }
else
k.to_sym
end
end
end
# Obtiene el tipo de campo para la plantilla # Obtiene el tipo de campo para la plantilla
def template_form_type_for(field) def template_form_type_for(field)
return if (tt = template.get_front_matter(field)).nil? return if (tt = template.get_front_matter(field)).nil?