Skip to content

Instantly share code, notes, and snippets.

@m4tm4t
Created August 11, 2013 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4tm4t/6204053 to your computer and use it in GitHub Desktop.
Save m4tm4t/6204053 to your computer and use it in GitHub Desktop.
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
@inossidabile
Copy link

removed comment

@inossidabile
Copy link

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