cancan_namespace 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -3
- data/lib/cancan_namespace/controller_resource.rb +1 -1
- data/lib/cancan_namespace/version.rb +1 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -34,17 +34,35 @@ Namespace for cancan gem.
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
In this case context extracted from controller name (:manage):
|
38
|
+
|
37
39
|
class Manage::PostsController < Manage::BaseController
|
38
40
|
before_filter :find_post, :only => [:edit, :update, :destroy]
|
39
41
|
authorize_resource
|
40
42
|
...
|
41
43
|
end
|
42
|
-
|
44
|
+
|
45
|
+
Set context for controller directly:
|
46
|
+
|
47
|
+
class People::RelationshipsController < Account::BaseController
|
48
|
+
before_filter :find_followed
|
49
|
+
before_filter :build_relation, :only => [:create]
|
50
|
+
before_filter :find_relationship, :only => [:destroy]
|
51
|
+
|
52
|
+
authorize_resource :relationship, :context => :account
|
53
|
+
|
54
|
+
...
|
55
|
+
|
56
|
+
end
|
57
|
+
|
43
58
|
=== View
|
44
59
|
|
45
|
-
<% if can? :edit, post
|
46
|
-
<%= link_to 'Edit',
|
60
|
+
<% if can? :edit, post %>
|
61
|
+
<%= link_to 'Edit', edit_post_path(post) %>
|
47
62
|
<% end %>
|
48
63
|
|
64
|
+
<% if can? :edit, post, :context => :manage %>
|
65
|
+
<%= link_to 'Edit (admin)', edit_manage_post_path(post) %>
|
66
|
+
<% end %>
|
49
67
|
|
50
68
|
Copyright (c) 2011 Aimbulance, released under the MIT license
|
@@ -18,7 +18,7 @@ module CanCanNamespace
|
|
18
18
|
module InstanceMethods
|
19
19
|
def authorize_resource_with_context
|
20
20
|
unless skip?(:authorize)
|
21
|
-
options = { :context => module_from_controller }
|
21
|
+
options = { :context => (@options[:context] || module_from_controller) }
|
22
22
|
@controller.authorize!(authorization_action, resource_instance || resource_class_with_parent, options)
|
23
23
|
end
|
24
24
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cancan_namespace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Igor Galeta
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-06-21 00:00:00 +03:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|