From aa9806d8f6649fdfa8280a1895698d201a9adde0 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 2 Jan 2020 15:05:28 -0300 Subject: [PATCH] optimizacion: no preguntar si es usuarie todo el tiempo solo funciona cuando le usuarie es usuarie del sitio. si es invitade, la pregunta se hace por cada post. --- app/controllers/posts_controller.rb | 1 + app/views/posts/index.haml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index fe8ad47d..4d999d9a 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -13,6 +13,7 @@ class PostsController < ApplicationController # TODO: Aplicar policy_scope @posts = @site.posts(lang: I18n.locale) @posts.sort_by!(:order, :date).reverse! + @usuarie = @site.usuarie? current_usuarie end def show diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index e50bdfa8..eab39338 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -42,7 +42,7 @@ - next unless post.categories.value.include?(@category) - if @layout - next unless post.layout.name == @layout - - next unless policy(post).show? + - next unless @usuarie || policy(post).show? %tr %td .handle @@ -73,11 +73,11 @@ %br/ = post.try(:order).try(:value) %td - - if policy(post).edit? + - if @usuarie || policy(post).edit? = link_to t('posts.edit'), edit_site_post_path(@site, post.id), class: 'btn' - - if policy(post).destroy? + - if @usuarie || policy(post).destroy? = link_to t('posts.destroy'), site_post_path(@site, post.id), class: 'btn',