switch_user 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -0
- data/app/controllers/switch_user_controller.rb +4 -0
- data/app/helpers/switch_user_helper.rb +4 -1
- data/config/routes.rb +4 -2
- data/lib/switch_user.rb +14 -6
- data/lib/switch_user/version.rb +1 -1
- data/rails/init.rb +1 -0
- metadata +5 -4
data/README.md
CHANGED
@@ -45,6 +45,11 @@ If there are too many users (in production), the switch_user_select is not a goo
|
|
45
45
|
= link_to user.login, "/switch_user?scope_id=user_#{user.id}"
|
46
46
|
= link_to admin.login, "/switch_user?scope_id=admin_#{admin.id}"
|
47
47
|
|
48
|
+
If you use it in a Rails 2 project, you have to add a route manually.
|
49
|
+
|
50
|
+
# config/routes.rb
|
51
|
+
map.switch_user '/switch_user', :controller => 'switch_user', :action => 'set_current_user'
|
52
|
+
|
48
53
|
Configuration
|
49
54
|
-------------
|
50
55
|
|
@@ -16,7 +16,10 @@ module SwitchUserHelper
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
if options.respond_to?(:html_safe)
|
20
|
+
options = options.html_safe
|
21
|
+
end
|
22
|
+
select_tag "switch_user_id", options,
|
20
23
|
:onchange => "location.href = '/switch_user?scope_id=' + encodeURIComponent(this.options[this.selectedIndex].value)"
|
21
24
|
end
|
22
25
|
end
|
data/config/routes.rb
CHANGED
data/lib/switch_user.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
-
require "rails"
|
2
|
-
|
3
1
|
module SwitchUser
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
if defined? Rails::Engine
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
config.to_prepare do
|
5
|
+
ApplicationController.helper(SwitchUserHelper)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
else
|
9
|
+
%w(controllers helpers).each do |dir|
|
10
|
+
path = File.join(File.dirname(__FILE__), '..', 'app', dir)
|
11
|
+
$LOAD_PATH << path
|
12
|
+
ActiveSupport::Dependencies.load_paths << path
|
13
|
+
ActiveSupport::Dependencies.load_once_paths.delete(path)
|
14
|
+
ActionView::Base.send :include, SwitchUserHelper
|
7
15
|
end
|
8
16
|
end
|
9
17
|
|
@@ -22,7 +30,7 @@ module SwitchUser
|
|
22
30
|
self.view_guard = lambda { Rails.env == "development" }
|
23
31
|
|
24
32
|
mattr_accessor :redirect_path
|
25
|
-
self.redirect_path = lambda { |request| request.env["HTTP_REFERER"] ? :back : root_path }
|
33
|
+
self.redirect_path = lambda { |request, params| request.env["HTTP_REFERER"] ? :back : root_path }
|
26
34
|
|
27
35
|
def self.setup
|
28
36
|
yield self
|
data/lib/switch_user/version.rb
CHANGED
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'switch_user'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switch_user
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Huang
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- config/routes.rb
|
55
55
|
- lib/switch_user.rb
|
56
56
|
- lib/switch_user/version.rb
|
57
|
+
- rails/init.rb
|
57
58
|
- switch_user.gemspec
|
58
59
|
has_rdoc: true
|
59
60
|
homepage: http://rubygems.org/gems/switch_user
|