flyerhzm/switch_user

Integration with cancan

Closed this issue · 3 comments

config.switch_back = true
config.controller_guard = lambda { |current_user, request, original_user|
current_user && current_user.admin? || original_user && original_user.super_admin?
}

I want to do current_user.has_role? :admin ||original_user && original_user.has_role? :admin. I have no super admin. How do I do this? I am not able to do it. If I try the original I get
NoMethodError - undefined method `admin?' for #User:0x007fbd44cc34f0:

If I tried this modified version of it

config.controller_guard = lambda { |current_user, request, original_user|
current_user && current_user.has_role? :admin || original_user && original_user.has_role? :admin}

I get errors like
config/initializers/switch_user.rb:59: syntax error, unexpected tSYMBEG, expecting '}' (SyntaxError)
...ser && current_user.has_role? :admin || original_user && ori...
... ^
/home/aravind/Documents/dev/gw-c4u/config/initializers/switch_user.rb:59: syntax error, unexpected tSYMBEG, expecting '}'
...er && original_user.has_role? :admin}

Syntax error indicates that it's a problem with the ruby code in your initializer file and not the gem. I suggest that you introduce some parenthesis and swap the braces to a do..end block on the failing line. Start with something simple and then fold in the complexity. Feel free to reopen the issue if you believe that this is a problem with the gem.

hey Icowell.

I tried this as well

config.redirected_path = lambda{|request,params| "/performers/performer_dashboard"}

I used no other condition. It still won't route. What am I doing wrong?

That looks fine. Put up a gist with a stack trace and the complete contents of your initializer and I'll have a look.