Forked from
PortalMEC / portalmec
1511 commits behind the upstream repository.
-
Mauricio Giacomini Girardello authoredMauricio Giacomini Girardello authored
bookmarks_controller.rb 925 B
class BookmarksController < ApplicationController
include Pundit
before_action :authenticate_user!
before_action :set_user
before_action :find_object, only: [:add_object, :remove_object]
# GET /bookmarks/1
# GET /bookmarks/1.json
def show
render partial: 'list' if params[:list] == 'true'
end
# POST /bookmarks/1/learning_object
def add_object
authorize @object
Bookmark.create(user: @user, bookmarkable: @object)
render json: { status: true } if request.xhr?
end
def list
render layout: false
end
# DELETE /bookmarks/1/learning_object
def remove_object
authorize @object
Bookmark.destroy Bookmark.where(user: @user, bookmarkable: @object)
render json: { status: true } if request.xhr?
end
private
def set_user
@user = current_user
end
def find_object
klass = params[:type].constantize
@object = klass.find params[:id]
end
end