Comments (4)
do you mean it works fine in development environment, but not production?
it's wierd, did you put the gem "switch_user" in development group in
Gemfile?
On Mon, Apr 11, 2011 at 8:20 AM, aunderwo <
[email protected]>wrote:
I have changed my config in an initializer to be
config.controller_guard == lambda { |current_user, request|
Rails.env.development? || (Rails.env.production? && current_user &&
current_user.admin?) }However in production switch_user always fails. Even if I change the lambda
to always return true it still fails. It seems that the config is not being
read. However I know the switch_user initializer is working since changing
config.provider to :authlogic causes an error since I am using devise.Reply to this email directly or view it on GitHub:
#7
Best regards,
Richard Huang
[email protected]
http://www.huangzhimin.com
http://www.huangzhimin.comhttp://rails-bestpractices.com
http://www.rubyslide.com
http://github.com/flyerhzm
@flyerhzm
from switch_user.
No the gem is available in all environments and I know the gem is active in production since the switch_user URL works but gives permission denied whether I'm admin or not. This is still the case even if the controller_guard lambda is just 'true'.
Can't quite figure how to debug this. I'm using Ruby 1.9.2 in case this makes a difference.
from switch_user.
OK tracked down the problem. The initializer config does get picked up.
The problem was copying the default config from the ReadMe has this line
config.view_guard == lambda { |current_user, request| Rails.env.development? }
note the double =. I copied and pasted this and caused errors using this. My switch_user.rb initializer is as below and works fine. Please note for the redirect to match the default config it should be
config.redirect_path = lambda { |request, params| request.env["HTTP_REFERER"] ? :back : root_path }
not I think
config.redirect_path = lambda { |request, params| '/' }
As can be found in the readme
SwitchUser.setup do |config| # provider may be :devise or :authlogic config.provider = :devise # available_users is a hash, # key is the model name of user (:user, :admin, or any name you use), # value is a block that return the users that can be switched. config.available_users = { :user => lambda { User.all } } # available_users_identifiers is a hash, # keys in this hash should match a key in the available_users hash # value is the name of the identifying column to find by, # defaults to id # this hash is to allow you to specify a different column to # expose for instance a username on a User model instead of id config.available_users_identifiers = { :user => :id } # available_users_names is a hash, # keys in this hash should match a key in the available_users hash # value is the column name which will be displayed in select box config.available_users_names = { :user => :email } # controller_guard is a block, # if it returns true, the request will continue, # else the request will be refused and returns "Permission Denied" # if you switch from "admin" to user, the current_user param is "admin" config.controller_guard = lambda { |current_user, request| Rails.env.development? || ( Rails.env.production? && current_user && current_user.admin?) } # view_guard is a block, # if it returns true, the switch user select box will be shown, # else the select box will not be shown # if you switch from admin to "user", the current_user param is "user" config.view_guard = lambda { |current_user, request| Rails.env.development? || ( Rails.env.production? && current_user && current_user.admin?) } # redirect_path is a block, it returns which page will be redirected # after switching a user. config.redirect_path = lambda { |request, params| request.env["HTTP_REFERER"] ? :back : root_path } end
from switch_user.
fixed, thanks for pointing it out.
from switch_user.
Related Issues (20)
- before_action not defined in Rails 3 HOT 4
- no instructions for API applications HOT 2
- installed the gem attempted to use the hamle switch_user_select HOT 5
- Current_user and true_user. HOT 4
- Example site has failing SSL cert
- devise_for :admin_users makes current_user always nil in SwitchUser config HOT 1
- Rails 6 deprecation warning 'Initialization autoloaded the constant SwitchUserHelper' HOT 5
- Accessing `original_user` seems to be broken HOT 1
- Switching to another user causes a duplicate request HOT 1
- Conditional redirect_path Based on Current User. HOT 1
- form_user is invalid and is not listed in SwitchUser#available_users HOT 2
- loader returen array and throws error: undefined method `where' for #<Array:0x000000086f88c8> HOT 14
- grouped_options_for_select bug for rails 3.2
- Need to add route for remember_me when wildcarding routes HOT 1
- Opt out of "don't store sign in ip and sign in timestamp when switching user" HOT 1
- original_user is nill HOT 4
- Add helper for logout to origin user HOT 2
- Problem in controller_guard block HOT 3
- Switch User Select Box = Nil HOT 1
- Release new version with relative_url_root support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from switch_user.