Giter VIP home page Giter VIP logo

Comments (14)

flyerhzm avatar flyerhzm commented on June 30, 2024

@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.

acesuares avatar acesuares commented on June 30, 2024

Yes Rails 3.2.21

from switch_user.

flyerhzm avatar flyerhzm commented on June 30, 2024

@acesuares then change User.all to User.load, that's it.

from switch_user.

acesuares avatar acesuares commented on June 30, 2024

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.

flyerhzm avatar flyerhzm commented on June 30, 2024

@acesuares sorry, try change to { :user => lambda { User } } instead

from switch_user.

acesuares avatar acesuares commented on June 30, 2024

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.

flyerhzm avatar flyerhzm commented on June 30, 2024

@acesuares sorry, long time not use rails 3, it should be User.scoped

from switch_user.

acesuares avatar acesuares commented on June 30, 2024

@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.

flyerhzm avatar flyerhzm commented on June 30, 2024

@acesuares I updated README for this

from switch_user.

acesuares avatar acesuares commented on June 30, 2024

great!

from switch_user.

acesuares avatar acesuares commented on June 30, 2024

The only problem would be that in rails < 4, people will have to install the initializer AND modify it...

from switch_user.

flyerhzm avatar flyerhzm commented on June 30, 2024

@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.

acesuares avatar acesuares commented on June 30, 2024

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.

acesuares avatar acesuares commented on June 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.