Sha256: 9b1e9556dfcf21895b0824f3fa1a53bb722cc592afc7e1ccb2725b913795b0af
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
module SwitchUserHelper def switch_user_select if available? if current_user options = "<option value=''>Guest</option>" else options = "<option selected='selected' value=''>Guest</option>" end SwitchUser.available_users.each do |scope, user_proc| user_proc.call.each do |user| current = send("current_#{scope}") if current and current.id == user.id options += "<option selected='selected' value='#{scope}_#{user.id}'>#{user.send(SwitchUser.display_field)}</option>" else options += "<option value='#{scope}_#{user.id}'>#{user.send(SwitchUser.display_field)}</option>" end end end select_tag "switch_user_id", options.html_safe, :onchange => "location.href = '/switch_user?scope_id=' + encodeURIComponent(this.options[this.selectedIndex].value)" end end def available? user = nil SwitchUser.available_users.keys.each do |scope| user = send("current_#{scope}") break if user end SwitchUser.view_guard.call(user, request) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
switch_user-0.4.1 | app/helpers/switch_user_helper.rb |
switch_user-0.4.0 | app/helpers/switch_user_helper.rb |