eliminar desde el panel

This commit is contained in:
f 2019-05-30 14:33:51 -03:00
parent e9a7625010
commit bae77d8c69
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
5 changed files with 34 additions and 3 deletions

View file

@ -104,6 +104,19 @@ class PostsController < ApplicationController
end
end
# Eliminar artículos
def destroy
@site = find_site
@lang = find_lang(@site)
@post = find_post(@site)
authorize @post
@post.destroy
redirect_to site_posts_path(@site, category: session[:category], lang: @lang)
end
private
# Solo permitir cambiar estos atributos de cada articulo

View file

@ -34,6 +34,12 @@ class PostPolicy < SuttyPolicy
usuaria? || post.author == usuarix.email
end
# Solo las usuarias pueden eliminar artículos. Lxs invitadxs pueden
# borrar sus propios artículos
def destroy?
update?
end
class Scope < SuttyPolicy::Scope
# Las usuarias pueden ver todos los posts
#

View file

@ -118,8 +118,16 @@
%br
%td= post.date.strftime('%F')
%td= link_to t('posts.edit'),
edit_site_post_path(@site, post, lang: @lang),
class: 'btn btn-info'
%td
- if policy(post).edit?
= link_to t('posts.edit'),
edit_site_post_path(@site, post, lang: @lang),
class: 'btn btn-info'
- if policy(post).destroy?
= link_to t('posts.destroy'),
site_post_path(@site, post, lang: @lang),
class: 'btn btn-danger',
method: :delete,
data: { confirm: t('posts.confirm_destroy') }
- else
%h2= t('posts.none')

View file

@ -254,3 +254,5 @@ en:
invalid_help: It looks like the form is incomplete. Check the red-colored fields to complete it.
sending_help: Saving, please wait...
blank: Nothing
destroy: Delete
confirm_destroy: Are you sure?

View file

@ -261,3 +261,5 @@ es:
invalid_help: Parece que el formulario no está completo. Verifica los campos marcados en rojo para completarlo.
sending_help: Guardando, por favor espera...
blank: En blanco
destroy: Borrar
confirm_destroy: ¿Estás segurx?