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 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
 
@@ -1,5 +1,9 @@
1
1
  class SwitchUserController < ApplicationController
2
2
 
3
+ unless Rails.version =~ /^3/
4
+ unloadable
5
+ end
6
+
3
7
  before_filter :developer_modes_only
4
8
 
5
9
  def set_current_user
@@ -16,7 +16,10 @@ module SwitchUserHelper
16
16
  end
17
17
  end
18
18
  end
19
- select_tag "switch_user_id", options.html_safe,
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
@@ -1,3 +1,5 @@
1
- Rails.application.routes.draw do
2
- match 'switch_user' => 'switch_user#set_current_user'
1
+ if Rails.version =~ /^3/
2
+ Rails.application.routes.draw do
3
+ match 'switch_user' => 'switch_user#set_current_user'
4
+ end
3
5
  end
data/lib/switch_user.rb CHANGED
@@ -1,9 +1,17 @@
1
- require "rails"
2
-
3
1
  module SwitchUser
4
- class Engine < Rails::Engine
5
- config.to_prepare do
6
- ApplicationController.helper(SwitchUserHelper)
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
@@ -1,3 +1,3 @@
1
1
  module SwitchUser
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
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: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
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