From 32d8ebd1e805cd4fd55fdee19e8818c93f2e0810 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 28 Sep 2018 15:10:10 -0300 Subject: [PATCH] por defecto la autora es la usuaria actual --- app/controllers/posts_controller.rb | 8 ++++++-- app/views/posts/_form.haml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 3a48aa20..b1059b2b 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -45,8 +45,12 @@ class PostsController < ApplicationController @post = Post.new(site: @site, lang: @lang, template: @template) @post.update_attributes(repair_nested_params(post_params)) - # El author no se modifica - @post.update_attributes({author: current_user.username}) + # Las usuarias pueden especificar una autora, de la contrario por + # defecto es la usuaria actual + if current_user.is_a? Usuaria + @post.update_attributes({author: params[:post][:author]}) + end + @post.update_attributes({author: current_user.username}) unless @post.author if @post.save redirect_to site_posts_path(@site, lang: @lang) diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index 13b1804f..99da1da2 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -24,7 +24,7 @@ = label_tag 'post_author', t('posts.author') - todxs = (@site.usuarias + @site.invitadxs).map(&:username) = select_tag 'post[author]', - options_for_select(todxs, @post.author), + options_for_select(todxs, @post.author || current_user.email), { class: 'form-control select2', data: { tags: true, placeholder: t('posts.select.placeholder'),