pundit: convert favorites to pundit.

This commit is contained in:
evazion
2020-03-18 03:06:25 -05:00
parent cc2b4abd09
commit f1f489c40b
4 changed files with 37 additions and 21 deletions

View File

@@ -1,10 +1,10 @@
class FavoritesController < ApplicationController
before_action :member_only, except: [:index]
respond_to :html, :xml, :json, :js
skip_before_action :api_check
rescue_with Favorite::Error, status: 422
def index
authorize Favorite
if !request.format.html?
@favorites = Favorite.visible(CurrentUser.user).paginated_search(params)
respond_with(@favorites)
@@ -19,6 +19,7 @@ class FavoritesController < ApplicationController
end
def create
authorize Favorite
@post = Post.find(params[:post_id])
@post.add_favorite!(CurrentUser.user)
flash.now[:notice] = "You have favorited this post"
@@ -27,6 +28,7 @@ class FavoritesController < ApplicationController
end
def destroy
authorize Favorite
@post = Post.find_by_id(params[:id])
if @post