Sha256: dcf92a3a9e672aecd42020053c1ce64f88ebf4a9672dc5dc5de7e99098b1f837
Contents?: true
Size: 1.37 KB
Versions: 7
Compression:
Stored size: 1.37 KB
Contents
= CancanNamespace Namespace for cancan gem. == Install gem 'cancan_namespace' == Usage class Ability include CanCanNamespace::Ability def initialize(user, context = nil) @context = context ... if user.admin? can :manage, :all can :manage, :all, :context => :manage end end end === Controller Manage::BaseController < ApplicationController protected def current_ability @current_ability ||= ::Ability.new(current_user, :manage) end end In this case context extracted from controller name (:manage): class Manage::PostsController < Manage::BaseController before_filter :find_post, :only => [:edit, :update, :destroy] authorize_resource ... end Set context for controller directly: class People::RelationshipsController < Account::BaseController before_filter :find_followed before_filter :build_relation, :only => [:create] before_filter :find_relationship, :only => [:destroy] authorize_resource :relationship, :context => :account ... end === View <% if can? :edit, post %> <%= link_to 'Edit', edit_post_path(post) %> <% end %> <% if can? :edit, post, :context => :manage %> <%= link_to 'Edit (admin)', edit_manage_post_path(post) %> <% end %> Copyright (c) 2011 Aimbulance, released under the MIT license
Version data entries
7 entries across 7 versions & 2 rubygems