Created
August 5, 2018 16:32
-
-
Save pavel-sazonov/afe9cb6f86132a5c59406fe5dfb76145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
if user | |
can :create, [Question, Answer, Attachment, Comment] | |
can %i[update destroy], [Question, Answer], user_id: user.id | |
can :destroy, Comment, user_id: user.id | |
can :destroy, Attachment, attachable: { user_id: user.id } | |
can :set_best, Answer, question: { user_id: user.id } | |
can %i[vote_up vote_down], Vote, votable: { user_id: user.id } | |
# can %i[vote_up vote_down], [Question, Answer] do |votable| | |
# !user.author_of?(votable)# && votable.voted_by(user).empty? | |
# votable.user_id != user.id | |
# end | |
can :cancel_vote, [Question, Answer], user_id: user.id | |
end | |
can :read, :all | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment