devise_roles 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -6
- data/lib/devise_roles/version.rb +1 -1
- data/lib/devise_roles.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 596c2a0547dc9bf660cab64f0a01eb9442ce393a
|
4
|
+
data.tar.gz: 31741231bec77ce243a84a223fc7126733b13c59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64f541563a399566a29aab499e8059cda5b6be838b3069f4b87d5258b6c03f48cb31f10ec08ae18db66584d7902a1b1ac75cd3cd00c349b1f8ba93b0f4afad79
|
7
|
+
data.tar.gz: 5dacda552d758939723a0a1bac61dd51942e70adaaa971222df6e67527505a08fdb181a513b8b92b2dc1c9a89e7ab661b25e75a34ad28f6461367bf16e6da33f
|
data/README.md
CHANGED
@@ -26,14 +26,14 @@ Also you need to include it in your Application
|
|
26
26
|
|
27
27
|
In your **application.rb** add This
|
28
28
|
```ruby
|
29
|
-
|
29
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
30
30
|
```
|
31
31
|
You can create and initializer and add next line to it, or just write at top of your controllers
|
32
32
|
```ruby
|
33
|
-
|
33
|
+
require 'encryption/encryption'
|
34
34
|
```
|
35
35
|
|
36
|
-
##
|
36
|
+
## Pre set up
|
37
37
|
|
38
38
|
To use this gem features, you should create table **Roles** and add roles to it.
|
39
39
|
|
@@ -80,20 +80,22 @@ And this is all for setting up.
|
|
80
80
|
|
81
81
|
Now you can go to learn methods for this *gem*.
|
82
82
|
|
83
|
-
##
|
83
|
+
## DeviseRoles Usage
|
84
|
+
|
85
|
+
Here is a list of available methods.
|
84
86
|
|
85
87
|
#### Enable only for Role
|
86
88
|
|
87
89
|
If you want to enable some page for exact Role only, use this method
|
88
90
|
```ruby
|
89
|
-
DeviseRoles.available_for_user_role(user_role_name, user_redirect_path)
|
91
|
+
DeviseRoles.available_for_user_role(user_role_name, current_user, user_redirect_path)
|
90
92
|
```
|
91
93
|
Here is some example how to use it
|
92
94
|
```ruby
|
93
95
|
def some_controller_method_name
|
94
96
|
# Implement it at the top
|
95
97
|
# In this example, current view would be available for admins only
|
96
|
-
DeviseRoles.available_for_user_role('admin', root_path)
|
98
|
+
DeviseRoles.available_for_user_role('admin', current_user, root_path)
|
97
99
|
|
98
100
|
# Some other code ...
|
99
101
|
# That would be run if user is not **admin**
|
data/lib/devise_roles/version.rb
CHANGED
data/lib/devise_roles.rb
CHANGED
@@ -3,7 +3,7 @@ require "devise_roles/version"
|
|
3
3
|
module DeviseRoles
|
4
4
|
def self.available_for_user_role(user_role_name, current_user, user_redirect_path)
|
5
5
|
if current_user.role.name != user_role_name
|
6
|
-
redirect_to
|
6
|
+
redirect_to user_redirect_path, alert: "You should be #{user_role_name} to view that page!"
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|