Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def current_account
- if session[:name].nil? or @current_account.nil?
- accounts = Account.find(:all,
- :conditions => ['name = ?',
- session[:name]])
- # Tricky here because detect will return nil, and the || operator will give me accounts.first
- # if no account exists for current_location
- @current_account = accounts.detect{ |each| each.location == current_location } || accounts.first
- else
- # The instance variable here, prevents me from needing to make that find call more then once per page
- # even if the current_account method is called many times in a view,
- @current_account
- end
- end
- # expose the method for the views
- helper_method :current_account
Add Comment
Please, Sign In to add comment