Skip to content

Instantly share code, notes, and snippets.

@ccashwell
ccashwell / restrict_by_request_type.rb
Last active November 29, 2018 22:32
CanCan Authorization: Restrict resources by request format JSON
# Lock down controller actions with CanCan based on request format.
class Ability
include CanCan::Ability
def initialize(user, format=nil)
user ||= User.new
can :index, Model if format == "application/json"
end
end