Created
August 11, 2013 08:55
-
-
Save m4tm4t/6204053 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
module ArticleAccess | |
extend ActiveSupport::Concern | |
included do | |
protect do |user, article| | |
## Guests | |
scope { where("publish_at < '#{Time.now}'") } | |
can :view | |
unless user.nil? | |
## Redactor | |
if user.has_role?(:redactor) | |
allowed_fields = %w(title subtitle) | |
scope { all } | |
can :create, allowed_fields | |
can :update, allowed_fields | |
cannot :destroy | |
end | |
end | |
end | |
end | |
end |
Ha. I was wrong. It was not the same. Yes, your code is totally ok.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
removed comment