diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index eead430..3818947 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -35,4 +35,5 @@ body { textarea.post-content { min-height: 80vh; font-family: monospace; + font-size: 90%; } diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 3a98367..9a017a2 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index 9e7af91..39b8cf4 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml new file mode 100644 index 0000000..ad9468f --- /dev/null +++ b/app/views/posts/_form.haml @@ -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') diff --git a/app/views/posts/edit.haml b/app/views/posts/edit.haml new file mode 100644 index 0000000..cc29197 --- /dev/null +++ b/app/views/posts/edit.haml @@ -0,0 +1,9 @@ +.container-fluid + .row + %h1 + = t('posts.editing') + = @post.title + + .row + .col + = render 'posts/form' diff --git a/app/views/posts/show.haml b/app/views/posts/show.haml index 7df0997..ce7bcf2 100644 --- a/app/views/posts/show.haml +++ b/app/views/posts/show.haml @@ -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} diff --git a/config/locales/en.yml b/config/locales/en.yml index c28e990..f271311 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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!' diff --git a/config/locales/es.yml b/config/locales/es.yml index 6092f60..07ca386 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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!'