Skip to content

Instantly share code, notes, and snippets.

@dwaynemac
Created June 29, 2015 20:29
Show Gist options
  • Save dwaynemac/19d570687ed55b37e115 to your computer and use it in GitHub Desktop.
Save dwaynemac/19d570687ed55b37e115 to your computer and use it in GitHub Desktop.
def set_local_current_account
return if current_user.nil?
measure 'set_local_current_account' do
padma_cur_acc = current_user.padma(!params[:refresh_current_account]).try(:current_account_name)
local_cur_acc = current_user.account_name
if padma_cur_acc && padma_cur_acc != local_cur_acc
current_user.current_account = Account.find_or_create_by_name(padma_cur_acc)
current_user.save
end
end
end
def redirect_to_set_current_account
return if current_user.nil?
measure 'redirect_to_set_current_account' do
@tries = 0
begin
unless current_user.current_account && current_user.accounts.include?(current_user.current_account)
redirect_to edit_me_current_account_path
end
rescue
@tries += 1
retry if @tries < 3
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment