5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-14 18:01:42 +00:00

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
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 private
# Solo permitir cambiar estos atributos de cada articulo # Solo permitir cambiar estos atributos de cada articulo

View file

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

View file

@ -118,8 +118,16 @@
%br %br
%td= post.date.strftime('%F') %td= post.date.strftime('%F')
%td= link_to t('posts.edit'), %td
edit_site_post_path(@site, post, lang: @lang), - if policy(post).edit?
class: 'btn btn-info' = 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 - else
%h2= t('posts.none') %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. invalid_help: It looks like the form is incomplete. Check the red-colored fields to complete it.
sending_help: Saving, please wait... sending_help: Saving, please wait...
blank: Nothing 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. invalid_help: Parece que el formulario no está completo. Verifica los campos marcados en rojo para completarlo.
sending_help: Guardando, por favor espera... sending_help: Guardando, por favor espera...
blank: En blanco blank: En blanco
destroy: Borrar
confirm_destroy: ¿Estás segurx?