generar los parametros correctos
This commit is contained in:
parent
e1961c5cad
commit
8c6af96d2f
4 changed files with 11 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in a new issue