Comments (14)
@acesuares actually loader is configurable, by default
config.available_users = { :user => lambda { User.all } }
loader
is lambda { User.all }
, I guess you are using old rails where User.all
returns an array, but you can change the config, see README
from switch_user.
Yes Rails 3.2.21
from switch_user.
@acesuares then change User.all
to User.load
, that's it.
from switch_user.
User.load gave the following error:
ActionView::Template::Error (wrong number of arguments (0 for 1..2)):
13: <ul class="right">
14: <% if current_user.role?(:superadmin) && Rails.env.development? %>
15: <li class="has-dropdown">
16: <%= switch_user_select %>
17: </li>
18: <% end %>
19: <% if current_user.role?(:admin) || current_user.role?(:superadmin) || current_user.role?(:statistiek) %>
config/initializers/switch_user.rb:8:in `block (2 levels) in <top (required)>'
app/views/inline_forms/_header.html.erb:16:in `_app_views_inline_forms__header_html_erb___2810128481613404564_53618560'
app/controllers/clients_controller.rb:41:in `index'
It started working with something like User.where('id > 0')
from switch_user.
@acesuares sorry, try change to { :user => lambda { User } }
instead
from switch_user.
Thanks, but that was of course the first thing I tried, now it says:
Completed 500 Internal Server Error in 118.5ms
ActionView::Template::Error (undefined method `map' for #<Class:0x00000007365040>):
13: <ul class="right">
14: <% if current_user.role?(:superadmin) && Rails.env.development? %>
15: <li class="has-dropdown">
16: <%= switch_user_select %>
17: </li>
18: <% end %>
19: <% if current_user.role?(:admin) || current_user.role?(:superadmin) || current_user.role?(:statistiek) %>
app/views/inline_forms/_header.html.erb:16:in `_app_views_inline_forms__header_html_erb___97426261078959190_79135600'
app/controllers/clients_controller.rb:41:in `index'
from switch_user.
@acesuares sorry, long time not use rails 3, it should be User.scoped
from switch_user.
@flyerhzm that works!
So why not build that in, apparently something changed and broke existing apps.
if Rails.version.to_i >= 4
config.available_users = { :user => lambda { User.all } }
else
config.available_users = { :user => lambda { User.scoped } }
end
Is that possible?
from switch_user.
@acesuares I updated README for this
from switch_user.
great!
from switch_user.
The only problem would be that in rails < 4, people will have to install the initializer AND modify it...
from switch_user.
@acesuares I don't have time to fix and test for rails < 4 now, I'd appreciate it if you could send me a pull request.
from switch_user.
Now, when I use:
config.available_users = { :user => lambda { User } }
the error is:
undefined method `map' for #<Class:0x000000062390a0>
but if I use
config.available_users = { :user => lambda { User.scoped } }
the error is:
comparison of Array with Array failed
and if I don't use config/initializers/switch_user.rb at all, the error is
comparison of Array with Array failed
But a couple of days ago, User.scoped worked fine.
I am sure I am doing something wrong.
from switch_user.
It seems, the comparison of Array with Array, comes from actionpack-3.2.21, line 477
grouped_options = grouped_options.sort if grouped_options.is_a?(Hash)
grouped_options looks like this:
{:Guest=>[["Guest", nil]], "User"=>[["[email protected]", "user_1"],["[email protected]", "user_2"]]}
If I disable the guest option,
config.helper_with_guest = false
then the problem goes away...!
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
- 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.