Module: SwitchUserHelper

Defined in:
app/helpers/switch_user_helper.rb

Defined Under Namespace

Classes: SelectOption

Instance Method Summary collapse

Instance Method Details

#switch_user_selectObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/switch_user_helper.rb', line 3

def switch_user_select
  return unless available?

  if provider.current_user
    selected_user = "user_#{provider.current_user.id}"
  else
    selected_user = nil
  end

  grouped_options_container = {}.tap do |h|
    SwitchUser.all_users.each do |record|
      scope = record.is_a?(SwitchUser::GuestRecord) ? :Guest : record.scope.to_s.capitalize
      h[scope] ||= []
      h[scope] << [record.label, record.scope_id]
    end
  end

  option_tags = grouped_options_for_select(grouped_options_container, selected_user)

  render :partial => "switch_user/widget",
         :locals => {
           :option_tags => option_tags
         }
end