5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-01 21:16:07 +00:00

wip de edicion de articulos

This commit is contained in:
f 2018-01-31 17:29:27 -03:00
parent 912da888f0
commit 851da77ce7
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
8 changed files with 80 additions and 1 deletions

View file

@ -35,4 +35,5 @@ body {
textarea.post-content {
min-height: 80vh;
font-family: monospace;
font-size: 90%;
}

View file

@ -9,4 +9,26 @@ class PostsController < ApplicationController
@site = find_site
@post = find_post(@site)
end
def edit
@site = find_site
@post = find_post(@site)
end
def update
p = post_params
# 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
binding.pry
end
private
def post_params
params.require(:post).permit(:title, :date, :tags, :categories, :content)
end
end

View file

@ -15,7 +15,9 @@ class Post
def initialize(site:, post:, front_matter: {})
@site = site
@post = post
@errors = []
# los errores tienen que ser un hash para que
# ActiveModel pueda traer los errores normalmente
@errors = {}
@front_matter = front_matter
new_post! unless @post

View file

@ -0,0 +1,24 @@
= form_tag site_post_path(@site, @post), method: :patch, class: 'form' do
.form-group
= submit_tag t('posts.save'), class: 'btn btn-success'
.form-group
= text_field 'post', 'title', value: @post.title, class: 'form-control',
placeholder: t('posts.title')
.form-group
= text_area_tag 'post[content]', @post.content, autofocus: true,
class: 'form-control post-content'
.form-group
= label_tag 'post_date', t('posts.date')
= date_field 'post', 'date', value: @post.date.strftime('%F'),
class: 'form-control'
%small.text-muted.form-text= t('posts.date_help')
.form-group
= label_tag 'post_categories', t('posts.categories')
= text_field 'post', 'categories', value: @post.categories.join(', '),
class: 'form-control'
%small.text-muted.form-text= t('posts.tags_help')
.form-group
= label_tag 'post_tags', t('posts.tags')
= text_field 'post', 'tags', value: @post.tags.join(', '),
class: 'form-control'
%small.text-muted.form-text= t('posts.tags_help')

View file

@ -0,0 +1,9 @@
.container-fluid
.row
%h1
= t('posts.editing')
= @post.title
.row
.col
= render 'posts/form'

View file

@ -2,6 +2,9 @@
%h1= @post.title
= link_to t('posts.edit'), edit_site_post_path(@site, @post),
class: 'btn btn-info'
.content
:markdown
#{@post.content}

View file

@ -7,3 +7,13 @@ en:
title: 'Sites'
footer:
powered_by: 'is developed by'
posts:
edit: 'Edit'
save: 'Save'
date: 'Publication date'
date_help: 'This changes the articles order!'
title: 'Title'
tags: 'Tags'
tags_help: 'Comma separated!'
categories: 'Categories'
categories_help: 'Comma separated!'

View file

@ -7,3 +7,11 @@ es:
title: 'Sitios'
footer:
powered_by: 'es desarrollada por'
posts:
edit: 'Editar'
save: 'Guardar'
date: 'Fecha de publicación'
date_help: '¡Esto cambia el orden de los artículos!'
title: 'Título'
categories: 'Categorías'
categories_help: '¡Separadas por comas!'