Created
June 29, 2015 20:29
-
-
Save dwaynemac/19d570687ed55b37e115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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