wip de edicion de articulos
This commit is contained in:
parent
912da888f0
commit
851da77ce7
8 changed files with 80 additions and 1 deletions
|
@ -35,4 +35,5 @@ body {
|
|||
textarea.post-content {
|
||||
min-height: 80vh;
|
||||
font-family: monospace;
|
||||
font-size: 90%;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
24
app/views/posts/_form.haml
Normal file
24
app/views/posts/_form.haml
Normal 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')
|
9
app/views/posts/edit.haml
Normal file
9
app/views/posts/edit.haml
Normal file
|
@ -0,0 +1,9 @@
|
|||
.container-fluid
|
||||
.row
|
||||
%h1
|
||||
= t('posts.editing')
|
||||
= @post.title
|
||||
|
||||
.row
|
||||
.col
|
||||
= render 'posts/form'
|
|
@ -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}
|
||||
|
|
|
@ -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!'
|
||||
|
|
|
@ -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!'
|
||||
|
|
Loading…
Reference in a new issue