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
def update
p = post_params
@site = find_site
@lang = find_lang(@site)
@post = find_post(@site)
@post.update_attributes(p)
@post.update_attributes(post_params)
if @post.save
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
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: [])
default_post_params = [:title, :date, :content, :slug, :cover,
:layout, :permalink, :dir,
{ lang: {} }, { tags: [] }, { categories: [] }]
params.require(:post).permit(default_post_params + @post.template_params)
end
end

View file

@ -227,6 +227,18 @@ class Post
end.keys
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
def template_form_type_for(field)
return if (tt = template.get_front_matter(field)).nil?