5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-03 23:55:46 +00:00

generar los parametros correctos

This commit is contained in:
f 2018-06-21 15:15:03 -03:00
parent e1961c5cad
commit 8c6af96d2f
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
4 changed files with 11 additions and 10 deletions

View file

@ -68,10 +68,6 @@ class PostsController < ApplicationController
# Solo permitir cambiar estos atributos de cada articulo
def post_params
default_post_params = [:title, :date, :content, :slug, :cover,
:layout, :permalink, :dir,
{ lang: {} }, { tags: [] }, { categories: [] }]
params.require(:post).permit(default_post_params + @post.template_params)
params.require(:post).permit(@post.template_params)
end
end

View file

@ -23,7 +23,9 @@ class Post
REJECT_FROM_FRONT_MATTER = %w[date slug draft ext].freeze
# datos que no traemos del template
REJECT_FROM_TEMPLATE = %w[date draft categories layout title ext tags date slug].freeze
DEFAULT_PARAMS = [:title, :date, :content, :slug, :cover,
:layout, :permalink, :dir,
{ lang: {} }, { tags: [] }, { categories: [] }]
# Trabajar con posts. Si estamos creando uno nuevo, el **site** y
# el **front_matter** son necesarios, sino, **site** y **post**.
@ -230,10 +232,13 @@ class Post
end.compact
end
# devuelve las plantillas como strong params
# devuelve las plantillas como strong params, primero los valores
# simples, luego los arrays y al final los hashes
def template_params
@template_params ||= template_fields.map do |k|
@template_params ||= (DEFAULT_PARAMS + template_fields.map do |k|
k.to_param
end).sort_by do |s|
s.is_a?(Symbol) ? 0 : 1
end
end

View file

@ -98,7 +98,7 @@ class Post
def to_param
if nested?
{ key.to_sym => {} }
elsif array?
elsif array? && multiple?
{ key.to_sym => [] }
else
key.to_sym

View file

@ -17,7 +17,7 @@
-# Si el template es un array, quiere decir que esperamos un array de hashes.
-# El valor vacío luego es reemplazado por un id temporal
- if template.array?
- name = [template.key, '', nf.key]
- name = [template.key, '0', nf.key]
- else
- name = [template.key, nf.key]
- if @post.new?